Skip to content
QuizMaker logoQuizMaker
Activity
Java Backend Interview Prep

No lessons available

CONTENTS

3. Spring Boot REST APIs and HTTP Codes

Connect REST principles, Spring Boot controllers, and common HTTP status codes.

Java Backend Interview Prep
1. Java Frameworks & Testing
May 29, 2026
23
A

REST in Practice

REST is an architectural style for resource-oriented communication over HTTP. A RESTful API exposes resources through predictable URLs and uses HTTP methods to express actions.

MethodTypical Meaning
GETRead a resource
POSTCreate or trigger processing
PUTReplace a resource
PATCHPartially update a resource
DELETERemove a resource

Common HTTP Codes

CodeMeaning
200OK
201Created
202Accepted
400Bad request
401Unauthenticated
403Authenticated but forbidden
404Resource not found
405Method not allowed
500Internal server error
502Bad gateway
503Service unavailable

Spring Boot Mapping

@RestController combines controller behavior with JSON response serialization. @GetMapping, @PostMapping, and related annotations map HTTP routes to Java methods.

Interview Scenario Practice

Scenario 1: 400 vs 404

Scenario: A client calls /customers/not-an-email and the API cannot parse the identifier.

Strong answer: Return 400 Bad Request when the request format or input is invalid. Return 404 Not Found when the request is valid but the resource does not exist.

Why it works: The status code tells the client whether to fix the request or treat the resource as absent.

Common mistake: Returning 500 for validation errors. That makes a client-side problem look like a server outage.

Scenario 2: POST vs PUT

Scenario: You need an endpoint to create a new order, but the server generates the order ID.

Strong answer: Use POST /orders. The server creates a new resource and commonly returns 201 Created.

Why it works: POST is appropriate when the server owns creation and the final resource identifier.

Common mistake: Using GET for creation because it is easy to test in the browser. GET should be safe and should not create state.

Scenario 3: Unauthorized vs Forbidden

Scenario: A logged-in user tries to access an admin-only endpoint.

Strong answer: Return 403 Forbidden. The user is authenticated but does not have permission.

Why it works: 401 means authentication is missing or invalid; 403 means identity is known but access is denied.

Common mistake: Using 401 and 403 interchangeably.

Share this article

Test your knowledge

Take a quick quiz based on this chapter.

mediumJava Backend Interview Prep
Quiz: REST and HTTP
8 questions8 min

0 comments

Please login to comment.
No comments yet.
Lesson 3 of 5 in 1. Java Frameworks & Testing
Previous in 1. Java Frameworks & Testing
2. Spring Core: IoC, DI, Beans, and Scopes
Next in 1. Java Frameworks & Testing
4. Hibernate ORM Interview Essentials
Back to Java Backend Interview Prep
Back to moduleCategories