APIs (Part 3)

What is POSTMAN/NEWMAN?

Postman/Newman are API testing and development tools used to send, save, and manage HTTP/HTTPS requests. They provide features such as request/response capturing, environment and global variable management, and scripting to streamline the API development process. Postman has a graphical user interface and is available as a browser extension or as a standalone application, while Newman is a command-line tool for running Postman collections.

What Is Idempotence?

From a RESTful service standpoint, for an operation (or service call) to be idempotent, clients can make that same call repeatedly while producing the same result. In other words, making multiple identical requests has the same effect as making a single request. Note that while idempotent operations produce the same result on the server (no side effects), the response itself may not be the same (e.g. a resource's state may change between requests).

The PUT and DELETE methods are defined to be idempotent. However, there is a caveat on DELETE. The problem with DELETE, which if successful would normally return a 200 (OK) or 204 (No Content), will often return a 404 (Not Found) on subsequent calls, unless the service is configured to "mark" resources for deletion without actually deleting them. However, when the service actually deletes the resource, the next call will not find the resource to delete it and return a 404. However, the state on the server is the same after each DELETE call, but the response is different.

GET, HEAD, OPTIONS and TRACE methods are defined as safe, meaning they are only intended for retrieving data. This makes them idempotent as well since multiple, identical requests will behave the same.

Difference between Put and Post?

PUT method is used to update resource available on the server. Typically, it replaces whatever exists at the target URL with something else. You can use it to make a new resource or overwrite an existing one. PUT requests that the enclosed entity must be stored under the supplied requested URI

POST is a method that is supported by HTTP and depicts that a web server accepts the data included in the body of the message, which is requested. POST is often used by World Wide Web to send user generated data to the web server or when you upload file.

KEY DIFFERENCES:

  • PUT method is called when you have to modify a single resource while POST method is called when you have to add a child resource.
  • PUT method response can be cached but you cannot cache PUT method responses.
  • You can use UPDATE query in PUT whereas you can use create query in POST.
  • In PUT method, the client decides which URI resource should have, and in POST method, the server decides which URI resource should have.
  • PUT works as specific while POST work as abstract.
  • If you send the same PUT request multiple times, the result will remain the same but if you send the same POST request multiple times, you will receive different results.
  • PUT method is idempotent whereas POST method is not idempotent.


What is Patch Method

Typically, PATCH is used exactly like PUT, except if we don’t send a tagLine field then it keeps its current value instead of obliterating it to null. PATCH, it’s a friendly update.

Trace Method

The HTTP TRACE method performs a message loop-back test along the path to the target resource, providing a useful debugging mechanism.

The TRACE method is used to invoke a remote, application-layer loop- back of the request message.
TRACE allows the client to see what is being received at the other end of the request chain and use that data for testing or diagnostic information.

The final recipient of the request should reflect the message received, excluding some fields described below, back to the client as the message body of a 200 (OK) response with a Content-Type of message/http. The final recipient is either the origin server or the first server to receive a Max-Forwards value of 0 in the request.