What are HTTP methods?

HTTP methods (also known as HTTP verbs) are used to indicate the desired action to be performed on a specified resource in an HTTP request. These methods indicate the type of action the client wants the server to perform on a specific resource. They are an essential part of the HTTP protocol and are used in RESTful APIs.

There are several common methods used in API calls, including:

  • GET: Retrieves data from a server. This is the most common method used for API calls and is typically used to retrieve information from a database.

  • POST: Submits data to a server for processing. This method is typically used to create a new resource on the server, such as creating a new user account or uploading a file.

  • PUT: Updates an existing resource on a server. This method is typically used to update information in a database, such as updating a user's profile information.

  • DELETE: Deletes a resource from a server. This method is typically used to remove information from a database, such as deleting a user account.

  • PATCH: updates a resource partially. This method is typically used to update specific fields of an existing resource on a server, rather than replacing the entire resource.

Example

To get an idea of how HTTP methods in an API call can be used in a transactional email, the process below describes an order confirmation process:

"A customer places an order on an e-commerce website. The website's server uses a POST method to submit the order data to the Flowmailer API to initiate a transactional email flow. Flowmailer uses the order data to generate and send a confirmation email to the customer, using a POST method. The customer receives the confirmation email and clicks on a link to view the order details.

The e-commerce website's server uses a GET method to retrieve the order details from Flowmailer's API and display them to the customer. The customer updates the order by adding an additional item. The e-commerce website's server uses a PUT method to update the order details on the email service provider's API. The Flowmailer API uses the updated order data to generate and send an updated confirmation email to the customer using a PUT method.

After the package is shipped, the e-commerce website's server uses a GET method to retrieve the tracking number from the email service provider's API and display it to the customer. If the customer request to cancel the order, the e-commerce website's server uses a DELETE method to cancel the order on the email service provider's API. It sends a cancellation email to the customer with the reason for the cancellation."