8 questions
HTTP interview questions and answers
Junior questions
1. Which main HTTP methods do you know, and which of them are idempotent?
Answer
GETreads a resource,POSTcreates one or triggers an action,PUTreplaces a resource,PATCHpartially updates it,DELETEremoves it. An idempotent method leaves the server in the same state whether the same request is sent once or many times.GET,PUTandDELETEare idempotent,POSTis not, andPATCHin general is not either.GETandHEADare also safe, meaning they do not change state.Follow-up question: How do you make a repeated
POSTsafe, for example for a payment?2. What classes of HTTP status codes are there? Give examples.
Answer
1xx are informational, 2xx mean success (
200 OK,201 Created,204 No Content), 3xx are redirects (301,302,304 Not Modified). 4xx mean a client error:400bad request,401not authenticated,403access forbidden,404not found. 5xx mean a server error, for example500or503. The right status matters because clients, caches and monitoring rely on it.Follow-up question: Which status do you return if the request data is well formed but breaks a business rule?
3. What is REST, and how do you design resource URLs properly?
Answer
REST is an architectural style where everything is a resource with an address, and actions on it are expressed with HTTP methods. URLs contain plural nouns, not verbs:
GET /users/42,POST /users, not/getUser. Nesting shows relationships, for example/users/42/orders. The server keeps no session state between requests, each request carries everything it needs.Follow-up question: How would you implement pagination and filtering in a REST API?
4. What are the
Content-TypeandAcceptheaders for?Answer
Content-Typedescribes the format of the message body, for exampleapplication/jsonormultipart/form-data, so the receiver knows how to parse it.Acceptin a request tells the server which response formats the client accepts. If the server cannot return a suitable format, it responds with406 Not Acceptable. A wrongContent-Typeoften means the server does not see the request body.Follow-up question: Which other headers do you often use in APIs?
5. How does
PUTdiffer fromPATCH?Answer
PUTreplaces the whole resource: the client sends the full representation, and fields missing from the body are treated as removed or reset.PATCHchanges only the fields that are sent.PUTis idempotent by definition,PATCHis not guaranteed to be, although it is often implemented idempotently. In practice edit forms more often usePATCH.Follow-up question: Can you create a resource with
PUT, and when does that make sense?
Middle questions
2. What is CORS, and why does the browser send a preflight request?
Answer
Under the same origin policy the browser blocks reading responses from another origin, meaning a different combination of protocol, domain and port. CORS lets the server explicitly allow this with headers such as
Access-Control-Allow-Origin. For non simple requests, for example withPUT,DELETEorContent-Type: application/json, the browser first sends anOPTIONSpreflight and checks the allowed methods and headers. CORS only restricts browsers, server side clients ignore it.Follow-up question: Why can you not combine
Access-Control-Allow-Origin: *with sending cookies?3. How does caching work in HTTP?
Answer
The server controls caching with the
Cache-Controlheader:max-agesets the freshness time,no-storeforbids caching,no-cacheallows caching only with revalidation, andprivateandpublicsay who may cache. For revalidation the server sends anETagorLast-Modified, and the client later sendsIf-None-MatchorIf-Modified-Since. If the resource has not changed, the server replies304 Not Modifiedwith no body. Static files with a hash in the name are cached for a long time withimmutable.Follow-up question: How do you invalidate users' caches after deploying a new frontend version?
Train these questions
Study the cards, answer by text or voice and get an AI grade. Needs a signed in account.
Answer out loud and get graded
Here you get the questions with model answers. In the ShortLesson app you answer yourself, by text or voice, and AI grades the answer against the rubric and asks a follow-up, like a real interviewer.
The app is coming to the stores soon.
In the knowledge base
Reference pages for the technologies on this topic: who maintains them, when to use them and what interviews ask.