1

I am designing a REST API.

I have a single resource that I want to be able to change the status of for different conditions e.g. the URI is:

Applications/{application_id}/

The possible status changes are to set the application to:

  1. Cancelled
  2. SignedOff
  3. Hold

Each status change will require different information e.g. a reason for cancelled, a date for signedoff.

What would be a good looking URI to handle this? I had thought of

  1. POST: Applications/{application_id}/Cancel
  2. POST: Applications/{application_id}/SignOff
  3. POST: Applications/{application_id}/Hold

but it doesnt seem right to me.

EDIT:

I should have mentioned that I was already planning POST: Applications/{application_id} to update an existing application with a full set of application data.

3 Answers 3

2

I would stick with one url for all statuses and have your Status object encapsulate all the different properties. These keeps your url from having words that look like actions and to be more restful.

POST: Applications/{application_id}/status

public class Status
{
   public string StatusType {get;set;}
   public string CancelReason {get;set;}
   public string SignOffDate {get;set;}
   ...
}
Sign up to request clarification or add additional context in comments.

1 Comment

This is also a nice solution.
0
POST: Applications/{application_id}?cancel=true

POST is used only for CREATE. I think put will be better option.

2 Comments

Right. I use Taffy framework for my API and usually the POST/GET methods are used to determine if you are altering info or just getting it. Then you would post params to alter the info how you want to. Though if you follow your patter you might want to reverse your thinking. Applicatins/cancel/id. It's easier to read.
cancel, signoff, hold are verbs. This is famous question though. Like Orders can get cancelled or deleted. How do you differentiate then? The most suggested answer is use query params like cancel=true, signoff=true or hold=true. When you do GET have a element <CANCEL>true</cancel> <signoff>false</signoff> like that.
0

For restful API, each endpoint is representing a resource as a noun. you are going to put an operation to the resource, and the operation can be divided into operations/hold, operations/cancel etc.

POST: Applications/{application_id}/operations/hold
POST: Applications/{application_id}/operations/cancel
POST: Applications/{application_id}/operations/signOff

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.