简体   繁体   中英

how to design REST API when resources have multiple states

I am going to design REST API for incident reporting in my web application. An incident has three states. ie investigation incident,resolved and postmortem. I use three database tables for each state.I want to design rest api for creating new incident to database. Here new incident means that incident in investigation state.

I have tried two approaches for designing rest api. In first approach I consider three states as sub resources.

POST - /incident/investigation
POST - /incident/resolved
POST - /incident/postmortem

In second approach, I think to pass incident state in http response of POST method.

POST-/incident

What is the best way to design REST API?

A REST API should identify the resource, so you'd have something like /incident/123 to denote incident number 123. And /incident/123/status would be the current status of that particular incident.

As each incident is in exclusively one state, you don't have the "multiple states" problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM