Interacting with an API requires a clear understanding of HTTP verbs. Each method has a specific purpose and semantic meaning.
1The Verbs of the Web
In a RESTful architecture, the URL identifies the 'resource' (e.g., /users), and the HTTP verb identifies the 'action'. GET is for reading, POST is for creating, PUT is for replacing, and DELETE is for removing. Adhering to these conventions makes your code more predictable and allows you to leverage standard browser and server behaviors, such as caching for GET requests.
2The Request Body
While GET and DELETE typically only require a URL, POST and PUT methods allow you to send a 'payload' or 'body'. Angular's HttpClient automatically serializes JavaScript objects into JSON for you. It also sets the correct headers, ensuring the server knows how to interpret the data you're sending. This automated serialization is one of the many ways Angular simplifies the developer experience.
