HTTP requests are sent from the client to the server to initiate some operation. In addition to the URL, HTTP requests have other elements to specify the requested resource.
Elements:
- Method: Defines the operation to be performed
- Path: The URL of the resource to be fetched, excluding the scheme and host
- HTTP Version
- Headers: optional information, success as Accept-Language
- Body: optional information, usually for methods such as POST and PATCH, which contain the resource being sent to the server.
Request Methods:
Different request methods indicate different operations to be performed. It’s essential to attend to this to correctly format your requests and properly structure an API.
- GET: ONLY retrieves information for the requested resource of the given URI. Retrieve some information from the backend.
- POST: Send data to the server to create a new resource
- PUT: Replaces all of the representation of the target resource with the request data
- PATCH: Partially modifies the representation of the target resource with the request data
- DELETE: Removes all of the representation of the resource specified by the URI
- OPTIONS: Sends the communication options for the requested resource.