0% found this document useful (0 votes)
7 views

Spring Boot Deep Dive - REST API

Uploaded by

Siddartha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Spring Boot Deep Dive - REST API

Uploaded by

Siddartha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Spring Boot

REST API

1
Introduction to REST
REST: Representational State Transfer
Architectural style for the web (makes use of HTTP)
Key abstraction - Resource
Todo Management Application
Examples: Users, Todos
Resource has URI (Uniform Resource Identifier)
/users/Ranga - (/users/{id})
/users/Ranga/todos - (/users/{id}/todos)
/users/Ranga/todos/1 - (/users/{id}/todos/{id})
You can perform ACTIONS on resources:
Retrieve/Add/Update/Delete Todo
Retrieve/Add/Update/Delete User
Resource can have different REPRESENTATIONS
JSON, XML (JSON - most popular)

2
Request Methods for REST API
GET - Retrieve details of a resource
POST - Create a new resource
PUT - Update an existing resource
PATCH - Update part of a resource
DELETE - Delete a resource

3
Response Status for REST API
Return the correct response status
Resource is not found => 404
Server exception => 500
Validation error => 400
Important Response Statuses
200 — Success
201 — Created
204 — No Content
401 — Unauthorized (when authorization fails)
400 — Bad Request (such as validation error)
404 — Resource Not Found
500 — Server Error

4
Survey Questionnaire REST API
Build a REST API for Survey
Questionnaire
Key Resources:
Surveys
Survey Questions
Key Details:
Survey: id, title, description, question
Survey Questions: id, description, options,
correctAnswer

5
Survey Questionnaire REST API - Resources and Methods
Survey REST API:
Retrieve All Surveys
GET /surveys
Retrieve Specific Survey
GET /surveys/{surveyId}
Survey Questions REST API:
Retrieve Survey Questions
GET /surveys/{surveyId}/questions
Retrieve Specific Survey Question
GET /surveys/{surveyId}/questions/{questionId}
Add Survey Question
POST /surveys/{surveyId}/questions
Delete Survey Question
DELETE /surveys/{surveyId}/questions/{questionId}
Update Survey Question
PUT /surveys/{surveyId}/questions/{questionId}
6
Slides For Future

7
Constraints defined by REST
Client - Server : Server (service provider) separated
from client (service consumer)
Benefits: Loose coupling, Independent evolution of server and
client (as new technologies emerge)
Each service should be stateless
Each Resource has a resource identifier
/users/Ranga - (/users/{id})
/users/Ranga/todos - (/users/{id}/todos)
/users/Ranga/todos/1 - (/users/{id}/todos/{id})
Caching response should be possible
Resource can have multiple representations
Resource can modified through a message in any of the these
representations

You might also like