Giter VIP home page Giter VIP logo

Comments (4)

md2perpe avatar md2perpe commented on July 19, 2024

The principle Nouns are good, verbs are bad doesn't mean that verbs can never be used. In some cases there are no natural ways to treat an action as a CRUD operation on a resource.

https://blog.apigee.com/detail/restful_api_design_tips_for_search

from restcookbook.

miguelgrinberg avatar miguelgrinberg commented on July 19, 2024

I agree with @SIOUF, the HATEOAS example is really misleading. In REST APIs all URLs must point to resources. If you have URLs that represent actions, then you are doing RPC (remote procedure call), which is a valid approach to implementing an API, but it is not REST.

A RESTful representation for your Account resources would offer the following links:

<link rel="deposit" href="/account/12345/deposits" />
<link rel="withdraw" href="/account/12345/withdrawals" />
<link rel="transfer" href="/account/12345/transfers" />

Sending a GET request to any of these returns transactions of that type. Sending a POST request creates a new transaction of the given type. PUT modifies a transaction, and DELETE (if allowed) deletes a transaction. To close an account you would not have a resource, you would either send a PUT request to the account resource and modify a state from open to closed, or else you can also send a DELETE request to the account resource.

The second part of the article, where a new resource representation is shown as having less links due to the account being in red is also incorrect. The links always exist and are always available, regardless of the account balance. If you send a POST request to the /withdrawals request and the account is in red, then the request will simply fail, maybe with a 403 (Forbidden).

from restcookbook.

jaytaph avatar jaytaph commented on July 19, 2024

Yes, i must agree with this, and it should be changed. I can make the changes, but due to lack of current time this might take a while. A pull-request with some updated info would be really helpful at the moment.

from restcookbook.

miguelgrinberg avatar miguelgrinberg commented on July 19, 2024

Okay, I'll see if I can come up with something in the next couple of days.

from restcookbook.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.