MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

Understanding REST HTTP method – GET, POST, PUT, HEAD, DELETE in Elasticsearch

REST (Representational State Transfer) was introduced and defined in 2000 by Roy Fielding in his doctoral dissertation. REST is an architectural style for designing distributed systems. It is not a standard but a set of constraints, such as being stateless, having a client/server relationship, and a uniform interface. REST is not strictly related to HTTP, but it is most commonly associated with it

Principles of REST

  • Resources expose easily understood directory structure URIs.
  • Representations transfer JSON or XML to represent data objects and attributes.
  • Messages use HTTP methods explicitly (for example, GET, POST, PUT, and DELETE).
  • Stateless interactions store no client context on the server between requests. State dependencies limit and restrict
  • scalability. The client holds session state.

HTTP methods
Use HTTP methods to map CRUD (create, retrieve, update, delete) operations to HTTP requests.

GET (Retrieve information)
Retrieve information. GET requests must be safe and idempotent, meaning regardless of how many times it repeats with the same parameters, the results are the same. They can have side effects, but the user doesn’t expect them, so they cannot be critical to the operation of the system. Requests can also be partial or conditional. example

POST (Create + Update)
Request that the resource at the URI do something with the provided entity. Often POST is used to create a new entity, but it can also be used to update an entity.

PUT (Create + Update)
Store an entity at a URI. PUT can create a new entity or update an existing one. A PUT request is idempotent. Idempotency is the main difference between the expectations of PUT versus a POST request.

DELETE (Remove)
Request that a resource be removed; however, the resource does not have to be removed immediately. It could be an asynchronous or long-running request.

Table of HTTP methods: GET reads, POST inserts, PUT or PATCH updates, DELETE deletes data

 

Table of HTTP status codes such as 200 OK, 404 Not Found and 500 Server Error with explanations

Status codes indicate the result of the HTTP request.

1XX – informational
2XX – success
3XX – redirection
4XX – client error
5XX – server error

PUT vs. POST in RESTful in Elastic Search

Note explaining PUT updates a full document while POST does a partial update of sent fields

A PUT request is idempotent. Idempotency is the main difference between the expectations of PUT versus a POST request.

PUT implies putting a resource – completely replacing whatever is available at the given URL with a different thing. By definition, a PUT is idempotent. Do it as many times as you like, and the result is the same. x=5 is idempotent.

You can PUT a resource whether it previously exists, or not (eg, to Create, or to Update)!

POST updates a resource and adds a subsidiary resource, or causes a change. A POST is not idempotent, in the way that x++ is not idempotent.

Good read here
https://stackoverflow.com/questions/630453/put-vs-post-in-rest

Overall, The PUT is used for update the existing values and POST is using to insert a new value.

At this URL(PUT) vs under this URL(POST)

PUT verb (“store this document at this URL“), we use the POST verb (“store this document under this URL“).

PUT /website/blog/123
{
  "title": "My first blog entry",
  "text":  "Just trying this out...",
  "date":  "2014/01/01"
}

Code language: JavaScript (javascript)
PUT vs POST vs PATCH comparison table describing how each inserts or updates a resource

Auto-generation of ids(POST) vs specify an id(PUT)

Autogenerated IDs are 20 character long, URL-safe, Base64-encoded GUID strings. These GUIDs are generated from a modified FlakeID scheme which allows multiple nodes to be generating unique IDs in parallel with essentially zero chance of collision.

Thus, only difference, that a POST can be used to achieve auto-generation of ids whereas a PUT is used when you want to specify an id.

It’s all about REST semantics. POST basically that you are posting a request which is going to modify the server state. POST index/type { “foo”: “bar” } will generate an _id server side and will index the document with this _id.

PUT is used to send a resource to the server. PUT index/type/id { “foo”: “bar” } will put or update a document named index/type/id in the server.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Inspect HTTP Requests Online: The Smarter Way to Debug APIs, Webhooks, and Request-Response Traffic

Here’s a polished blog draft you can use. Inspect HTTP Requests Online: The Smarter Way to Debug APIs, Webhooks, and Request-Response Traffic Modern applications rely heavily on…

Read More

Comprehensive Guide to Communication Protocols

This guide covers the most common communication protocols used in modern cloud-native architectures, compares their capabilities, and discusses when to use each. It also analyzes support and…

Read More

How to Send a POST Request with Python

Introduction Most tutorials focus on GET requests, but working with an API frequently requires using POST requests as well. Web servers don’t randomly send data; a request…

Read More

What is Webhook?

A webhook is an HTTP-based callback function that allows lightweight, event-driven communication between two application programming interfaces (APIs). When an event occurs in one system, the webhook…

Read More

What is REST API

REST is acronym for REpresentational State Transfer. It is architectural style for distributed hypermedia systems and was first presented by Roy Fielding in 2000 in his famous. Guiding Principles of REST Client–server â€“…

Read More

RESTful Services in Web API.

RESTful Service Structure Let’s have a look at the structure a RESTful service generally has, or how it works. Here we have, well, parts of a RESTful…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x