Home > Enterprise >  API Validating basket on get request
API Validating basket on get request

Time:05-04

What would be the best approach to handle Model State Errors for the the basket to the user that loads the basket from the API ?

Scenario:

  1. User adds product to the basket ( basket is valid at the time of creating it )
  2. The product is taken off ( for example has been set as not available or the price has changed since the user added to the basket ) ( this can be done outside API )

Should the client make two requests:

  1. Get The basket
  2. Validate the basket ( a little bit RPC style )

Another way of doing it might be extending the response view model with 'errors' that might get populated whenever user GET it via API. Not sure though if this is good practice though.

What would be the RESTful way of solving this problem ?

Thanks in advance for help

CodePudding user response:

What would be the RESTful way of solving this problem ?

How would you do it with a web page?

It would probably be a single web page, right? Containing

  • a list of items in the basket, and...
  • a list of problems that might prevent the order from growing through
    • and maybe also some links to other resources that might help resolve these problems.
    • otherwise forms, or links to forms, to aid in performing the next step of the ordering protocol.

Another way of doing it might be extending the response view model with 'errors' that might get populated whenever user GET it via API. Not sure though if this is good practice though.

It's fine - the resource model is not the domain model is not the data model. Your "resources" are documents that support interacting with the domain.

See also: Webber 2011.

  • Related