Giter Site home page Giter Site logo

Comments (2)

darrelmiller avatar darrelmiller commented on May 3, 2024

I wouldn't recommend using 404 to indicate an empty shopping cart. If there is an explicit process to create a cart and delete a cart then a 404 would indicate the need to create a cart. A client that requests to see the contents of the cart when the cart is empty, is not a "client error". At least that is quite a stretch.

Assuming that carts are implicitly created when you add items to them, there are two options for indicating an empty cart. You can return a 200 and a empty object/array, or return a 204 that has no response body at all.

from api-guidelines.

zaverden avatar zaverden commented on May 3, 2024

See here: https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#51-errors

4xx indicates that client has sent an invalid request (wrong path, bad format, unsupported method, etc.). And if I get you description right, then empty card is not a problem, it is a valid state of application => 404 does not suet here.

200 vs 204 is like empty array vs null. Decision here depends on you style and preferences.
Personally, I prefer to have 200 and be sure that I always receive array (empty or not) in a response body.

from api-guidelines.

Related Issues (20)

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.