Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes

## [2.1.0 (2024-09-28)](https://github.com/axe-api/axe-api/compare/2.1.0...2.0.1)

- Added missing requests to the Resource object

## [2.0.1 (2024-09-28)](https://github.com/axe-api/axe-api/compare/2.0.1...2.0.0)

- Fixed bundling issues
Expand Down
113 changes: 35 additions & 78 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "axe-api-client",
"version": "2.0.1",
"version": "2.1.0",
"description": "axe-api-client is a native JavaScript client for Axe API servers.",
"type": "module",
"main": "dist/index.cjs",
Expand Down Expand Up @@ -34,7 +34,7 @@
"@babel/preset-typescript": "^7.24.7",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"eslint": "^8.57.1",
"fetch-mock": "^9.11.0",
"fetch-mock": "^11.1.5",
"husky": "^9.1.6",
"jest": "^29.7.0",
"lint-staged": "^15.2.10",
Expand Down
18 changes: 18 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ const response = await api.resource("users").insert({
});
```

## Post

```js
const response = await api.resource("users").post({
name: "Karl",
surname: "Popper",
});
```

## Update

```js
Expand All @@ -74,6 +83,15 @@ const response = await api.resource("users").patch({
});
```

## Put

```js
const response = await api.resource("users").put({
name: "Karl",
surname: "Popper",
});
```

## Delete

```js
Expand Down
55 changes: 37 additions & 18 deletions src/Resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,44 +484,63 @@ export class Resource implements IQueryable {
}

/**
* Patch the resource
* Paginate the resource
*
* @param data object
* @param query IPaginate
* @returns object
*/
async patch(data: object) {
return this.sendRequest("PATCH", data);
async paginate(query?: IPaginate): Promise<IPagination> {
this.params.append("page", query?.page?.toString() ?? "1");
this.params.append("per_page", query?.perPage?.toString() ?? "10");
return this.sendRequest("GET");
}

/**
* Delete the resource
* Get the resource
*
* @param data object
* @returns null
* @returns object
*/
async delete() {
this.sendRequest("DELETE");
async get() {
return this.sendRequest("GET");
}

/**
* Paginate the resource
* Send a POSt request
*
* @param query IPaginate
* @param data FormBody
* @returns object
*/
async paginate(query?: IPaginate): Promise<IPagination> {
this.params.append("page", query?.page?.toString() ?? "1");
this.params.append("per_page", query?.perPage?.toString() ?? "10");
return this.sendRequest("GET");
async post(data?: FormBody) {
return this.sendRequest("POST", data);
}

/**
* Get the resource
* Send a PUT request
*
* @param data FormBody
* @returns object
*/
async get() {
return this.sendRequest("GET");
async put(data?: FormBody) {
return this.sendRequest("PUT", data);
}

/**
* Send a PUT request
*
* @param data FormBody
* @returns object
*/
async patch(data?: FormBody) {
return this.sendRequest("PATCH", data);
}

/**
* Send a DELETE request
*
* @returns null
*/
async delete() {
return this.sendRequest("DELETE");
}

private async sendRequest(method: MethodType, data?: FormBody) {
Expand Down
Loading