Created for a demo purpose
-
What is REST API? REST stands for REpresnatation State Transfer API stands for Application Programming Interface We use this mechanism to contact between two computers and transfer information
-
Flexible It's not a specification, rather some suggested rules and depends on the creator. For example:
- https://api.example.com/products
- https://example.com/api/products
- https://api.example.com/v1/products
- https://api.example.com/v1/getAllProducts As we can see that all the above 4 API URI will return products, but the way they are structured are different and depends on the creator. ReST API doesn't depends on URI structure as there are no specification. API creator can still use any of the above 4 structure and handle on server.
It's suggested to use NOUN i.e. products rather then VERB getAllProducts.
-
What are C.R.U.D? POST ====request====> Create GET ====request===> Read PUT ===request===> Update DELETE ===request==> Delete
Here POST,GET,PUT and DELETE are verb
-
Status code A status code tells the requester about there request. Requester can do the next dependent things on previous API calls like when a user is registered, and server responded with 200 status code, then fire email this user.
All the status codes are grouped or we can say level 200 ====> Success "200": "OK", "201": "Created", "202": "Accepted", "203": "Non-Authoritative Information", "204": "No Content",
400 ====> Something not correct at requester end, like required information not passed, or format is not correct.
"400": "Bad Request", "401": "Unauthorized", "402": "Payment Required", "403": "Forbidden", "404": "Not Found", "405": "Method Not Allowed", "406": "Not Acceptable", "407": "Proxy Authentication Required", "408": "Request Timeout", "429": "Too Many Requests", "431": "Request Header Fields Too Large", "451": "Unavailable For Legal Reasons",
500 ====> Something went wrong at server level, like server went down or timeout happened "500": "Internal Server Error", "501": "Not Implemented", "502": "Bad Gateway", "503": "Service Unavailable", "504": "Gateway Timeout", "505": "HTTP Version Not Supported", "508": "Loop Detected", "510": "Not Extended", "511": "Network Authentication Required"
We can have our own status code and there definition.
-
API should be well documented.
-
It should be stateless
-
Always write test cases <-- will do soon on the demo as well.