Is POST for an element generally not exposed or invalid in REST APIs?

I was browsing around wikipedia on REST, reading specifically the section on REST APIs

Reading the different ways to treat elements from collections I read that POST is not generally used.

How does that work in practice? When successful REST APIs are developed, when it comes to elements, does POST just not exist or return an error?

Is there a reasoning behind that I haven’t grasped?

3

According to the RFC for HTTP, which most REST APIs build upon, the meaning of the methods is:

  • GET: Retrieve a resource
  • POST: Add a sub-entity to a resource
  • PUT: Create or replace a resource
  • DELETE: Remove a resource

In common usage, POST is also often used to modify a resource by indicating the changes that must be applied.

The main distinction between POST and PUT is that you should use PUT if you already know the exact URI of the resource you are creating, and POST if you only know the collection that will hold the resource.

As for the usage in REST APIs, I would recommend to use POST for adding resources to a collection and for modifying resources piecewise. If neither makes sense, then you should return a 405 (Method Not Allowed) error.

I’ve seen a lot of confusion from people over what POST actually means. It does not mean create, and it does not mean update. POST means “send a message to a resource without the expectation of idempotency”. The other basic HTTP methods are all idempotent: if you do the same thing twice, you get (morally) the same result.

Let’s clarify. When you use POST twice in a row, sending the same message to the same resource, you are nevertheless anticipating different results from the two operations. This can map quite nicely to creation where the server is creating new resource URIs in response to the messages: different URIs, non-idempotent. On the other hand, if the client is making the URI (a common case where you’re modelling a filesystem) then POST is the wrong thing for creation: PUT to the resource you want to create is more typically correct there (and PUTting the same content to the same URI twice results in the same thing: the content exists afterwards at that URI whether or not it existed beforehand).

It is important to realise that REST is not just about simply having collections and values in those collections. It can do much more than that (though in that case you have to do more work to make it all discoverable).

Philosophically, it is a hard question… There are schools of thoughts about REST, and nobody is right or wrong.

The way I develop my rest APIs is simple:

  • GET – Read an element
  • PUT – Update an element
  • POST – create an element
  • DELETE – Delete an element

The Wikipedia entry say that PUT can be used for create or replace. Sure it can be done that way, but I find it clearer (and it is subjective) so separate the 2 actions.

It all comes down to a matter of taste.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật