How to Post to an API

Whether you're working on a website or an API, knowing how to post to an API is an important step on the development path. You'll want to be confident in your request methods to maximize the use of resources. By understanding the difference between POST and PUT, you'll be able to make more informed choices.


A POST request is a very common HTTP method that can be used to send data to an API. This may include updating an existing resource, generating a new record, or pushing data into a database. A POST request has no limits on data length. However, a POST request can have some unintended consequences.


In the simplest form of a POST request, you'll be sending data to the server through a web form. Your data may be in JSON or XML format.


When you're looking to send a POST request, you should consider implementing the Content-Type header. This allows the server to understand what your body format is. In addition, you'll want to add an Accept header with your POST request. The Accept header can be set to either application/xml or application/json.


The POST method is a bit more advanced than the PUT method. The PUT method simply updates an existing resource. The POST method creates a new resource. A POST is also idempotent. In other words, if you submit the same POST request, the same response will be sent to you.


The POST method is most commonly used in ajax-based form processing. In a contact form, you can use a POST method to submit your phone number, email address, and course name.