Requests
ShapeRQ supports all HTTP methods:
GET - get data
POST - send data
PATCH - update data with partial overwrite of the object
PUT - update data with full overwrite of the object
DELETE - delete the object
HEAD - get headers, check resource exictence
OPTIONS - get inforamtion about supported methods
import {
httpGet, httpPost, httpPut, httpPatch,
httpDel, head, options
} from "shape-rq"
Request without body
httpGet<UserType>("MyAPI", "users/")
.then(data => {
console.log(data)
})
// OR
const res = await httpGet("MyAPI", "users/")
console.log(res)
httpDel(
"MyAPI",
"auth/users/1/"
).then(
...
)
Requests with body
httpPost(
"MyAPI",
"auth/users/",
{
body: {
username: "JohnDoe",
password: "12345678"
},
}
).then(
...
)
A simple template of POST
request, there three paramters:
API
endpoint
options -> body
In the body, we pass the data of our request, what we send to the server, in the form of a record <string, any> or FormData or just string
Last updated