No matter which programming language or technology you’re working with, you’ve probably encountered a REST application programming interface (API). REST stands for Representational State Transfer, which is the one of the most widely-used architectural styles for web services, microservices, and APIs today. APIs that follow the REST architectural style are considered REST APIs.
Whether you’re a junior or senior developer, you may be asked questions about REST API in an interview. To help you ace your next interview, we’ll discuss some common REST API interview questions and answers.
We’ll cover:
In case they ask for 6 constraints, see the following question about the optional constraint.
A truly RESTful API must conform to the five REST architectural constraints:
Code on demand is the optional constraint of RESTful architecture. Code on demand allows the server to send executable code (scripts or applets) to a client upon client request.
Advantage: Extends client functionality, since client can download features after deployment
Disadvantage: Reduces visibility, which is why it’s considered optional
Examples: Java applets and JavaScript
A uniform interface is needed to decouple the client from the server.
There are four necessary constraints to achieving uniform interface:
CRUD is an acronym for the four basic operations used in relational database management system (RDBMS).
Each operation in CRUD relates to an HTTP method that REST supports.
POST
GET
PUT
DELETE
REST APIs are based on HTTP requests or verbs, which each perform a different task.
REST supports the following HTTP requests:
PUT:
POST:
Understanding idempotency: An example of an idempotent operation would be the operation of multiplying a number by one. No matter how many times you multiply five by one, you’ll get the same result.
Statelessness means that the client and server don’t store information about each other’s state. Since the server stores no information, it treats each client request as a new request.
As a consequence, the following conditions would apply:
It’s important to know the pros and cons of a RESTful API.
Advantages include:
Disadvantages include:
The distinction can confuse beginner developers, so it’s helpful to know the difference.
An AJAX client can make a RESTful request to a REST API (e.g. a get request), but AJAX isn’t an architectural style. It’s a web development technique for client-side applications. REST APIs can be accessed by AJAX clients, but they aren’t inherently implemented with AJAX.
SOAP:
REST:
HTTP response codes indicate the result of client requests.
Common HTTP status codes include:
Congratulations! You’re now prepared with some common REST API interview questions and answers. Where you go from here depends on your goals.
For interview prep, check out Interview Prep with Educative. Here, you’ll find all our resources for interview prep in one place, from tutorials and practice problems, to tips from industry experts.
To get hands-on with REST APIs, check out one of our interactive REST API courses:
Happy learning!
Join a community of more than 1.3 million readers. A free, bi-monthly email with a roundup of Educative's top articles and coding tips.