Using the REST API
These are some general instructions for using REST API. The API will allow us to perform CRUD operations. The format is given below.
GET
This is the operation for getting data from the API using a GET request. It follows a format of:
/products
This fetches all data available. An ID may be added to the endpoint to fetch a particular resource
/products/1
Query params may be added to the GET request to filter data
/product?category_id=1
/product?category_id=1&is_active=0
POST
This is the operation for creating data. We use a POST request and send our data as JSON. A POST request may have a post similar to this
{
"name": "John",
"age": 25,
"address": "P. Sherman, 42, Wallaby Way, Sydney"
}
PATCH
This is the operation for updating data. We use a PATCH request and send our data as JSON similar to a POST request but we add the resource ID to the endpoint.
/customer/25
{
"name": "John Smith",
"age": 25,
"address": "P. Sherman, 42, Wallaby Way, Sydney"
}
Unchanged fields may be omitted in a PATCH request
DELETE
This is the operation for deleting data. For this operation we may simply use the endpoint with the id in it to delete the resource
/customer/25
Note
These are general guidelines. There may be exceptions to this information and for further clarification look into the documentation of the concerned resource