Sample Prototype For REST API Design And Implementation

Sample Prototype For REST API Design And Implementation

It’s a sample prototype  REST APIs which actually interacts with Question/Answers based data models on the backend (e.g. see any question/answers based website like stackoverflow)

So here two steps to design the interface of REST APIs, mostly CRUD operations.

C- Create

R- Retrieve

U – Update

D-Delete

Step-1: Identify Noun As Resource and Its Definition

@Mandatory

Question ID: INT: “Unique Id” : java.util.UUID.randomUUID();

  • ID would be unique
  • Success – @If Its Unique
  • Failure – @If Its not Unique

@Mandatory

Question Title: Text: STRING: Max 180 Chars , Min 15 Chars

  • Max length of the Question would be 180 Chars
  • Chars would be alphanumeric, English Language
  • Charset UTF-8
  • Success – If length in between 15 to 180 chars
  • Failure – If length less than 15 or greater than 180 chars

@Mandatory // Only at the time of Creation // Min 3 Tags and Max 5 Tags

Question Tags: STRING: “ 5 Tags with Max – 25 Character on each Tag”

  • Max length of the Tag would be 25 Chars
  • Chars would be alphanumeric, English Language
  • Charset UTF-8
  • Success – If Tags are under the restrictions
  • Failure – If Tags are not under the restrictions

Question State: Enumerator: “Created, Answered, Closed, Rejected, Modification, Pending, Banned, Approved”

  • Created – > Answered, Rejected, Pending, Banned
  • Approved -> If ‘Rejected, Pending, Banned’, and after modification it can approved
  • Modification -> Approved
  • Success – If Correct states are followed
  • Failure – If InCorrect States are followed

Step-2: Identify Verbs As Actions

@Path(“/Questions/)

 

Verb What it does Comments
Create
QuestionDetail :

QuestionDetail As Parameter

Return :

Question Summary

Create a new question

createQuestion

 

Scenario: user add the details, and submitted to this web services. If all is well question got Created.

Default Status – Created

 

Request type : Post

If created return 201

If Request Input Error : 400

URL : (“/Questions/Create)

 

Update
Based on Question ID

Update the Title

Update the Tags

Update the Status

Update the Title or Tags Or Status of a Created Question

updateQuestionParams

Request type : PUT

If updated return 201

If update Input Error : 400

URL : (“/Questions/Update)
Delete
Delete the Question By ID Deletes Question

deleteQuestion

Set the Status as ‘Deleted’

Request type : Delete

If deleted return 201

If delete Input Error : 400

URL : (“/Questions/Delete)
Retrieve
 URL : (“/Questions/Retrieve”)  
Retrieve based on ID Retrieve Question based on given ID

getQuestionByID

Request type : GET

If retrieved return 201

If retrieve Input Error : 400

Retrieve based on single Tag Retrieve Questions based on given Tag

getQuestionByTag

Request type : GET

If retrieved return 201

If retrieve Input Error : 400

Retrieve based on multiple Tags Retrieve Questions based on multiple tags

getQuestionByTags

Request type : GET

If retrieved return 201

If retrieve Input Error : 400

Retrieve based on Status Retrieve Questions based on the Status

getQuestionByStatus

Request type : GET

If retrieved return 201

If retrieve Input Error : 400

Retrieve Status based on given Question ID

 

Retrieve Status based on given Question ID

getQuestionStatusByID

Request type : GET

If retrieved return 201

If retrieve Input Error : 400

Retrieve Tags based on given Question ID

 

Retrieve Tags based on given Question ID

getQuestionTagsByID

Request type : GET

If retrieved return 201

If retrieve Input Error : 400

 

 

 *Above just to provide an Idea about the interfaces of REST APIs without actually diving into any technical details.

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s