API design
What does REST stand for
REST is an architectural style for building distributed systems based on hypermedia. REST is independent of any underlying protocol and is not necessarily tied to HTTP.
REST APIs are designed around a resources, which are any kind of object, data, or service that can be accessed by the client.
What is an identifer of a resource? it is the URI that uniquely identifies that resource
and as an example https://adventure-works.com/orders/1
What are the most common HTTP verbs
-
GET retrieves a representation of the resource at the specified URI. The body of the response message contains the details of the requested resource.
-
POST creates a new resource at the specified URI. The body of the request message provides the details of the new resource. Note that POST can also be used to trigger operations that don’t actually create resources.
-
PUT either creates or replaces the resource at the specified URI. The body of the request message specifies the resource to be created or updated.
-
PATCH performs a partial update of a resource. The request body specifies the set of changes to apply to the resource.
-
DELETE removes the resource at the specified URI.
What should the URIs be based on
URIs should be based on nouns (the resource) and not verbs (the operations on the resource).
https://adventure-works.com/orders // Good
What does it mean to have a ‘chatty’ web API? Is this a good or a bad thing?
it means expose a large number of small resources. Such an API may require a client application to send multiple requests to find all of the data that it requires. and we should avoid that
What status code does a successful and unsuccessful GET request return?
A successful GET method typically returns HTTP status code 200 (OK). If the resource cannot be found, the method should return 404 (Not Found).
What status code does a successful POST request return?
If a POST method creates a new resource, it returns HTTP status code 201 (Created). The URI of the new resource is included in the Location header of the response. The response body contains a representation of the resource.
What status code does a successful DELETE request return?
If the delete operation is successful, the web server should respond with HTTP status code 204 (No Content), indicating that the process has been successfully handled, but that the response body contains no further information. If the resource doesn’t exist, the web server can return HTTP 404 (Not Found).
ALL the above information was token from https://docs.microsoft.com/en-us/azure/architecture/best-practices/api-design