All jobs / Backend developer / API Development
Backend developer interview question · 0–1 years
The interviewer asks: “How do you send and read JSON on an HTTP API?” Strongest answer?
The strongest answer
Set Content-Type: application/json, declare Accept, and (de)serialize with the language's JSON library — don't guess from the string.
Why it works
Exactly. The header is the contract. A serializer handles unicode, escaping and types; guessing invites mismatches and injection.
What a good answer covers
- JSON is a media type, not a vibe.
- Set Content-Type and Accept.
- Use a real serializer both ways.
- Never concatenate user text into JSON.
Answers that fall short
- Close, but not the strongest: Return JSON and let the client JSON.parse it; the header is optional if both sides know.
Clients and proxies do look at Content-Type. Skipping it works on your laptop and fails in a gateway or a typed client. - Weak: Return JSON as a string field inside XML so older clients still work.
A private string-in-XML nest is two formats and zero interop. Pick JSON and version the API if you must change shape. - Red flag: Build JSON by concatenating user text: '{"name":"' + name + '"}' — faster than a serializer.
Hand-built JSON is how you ship broken documents and XSS. Always serialize.
Who gets asked this
More API Development questions
- The interviewer asks: “What status do you return when POST creates a resource?” Strongest answer?
- The interviewer asks: “When do you nest URLs like /orders/12/items?” Strongest answer?
- In a GraphQL API, what is the schema and what is a resolver?
- The interviewer asks: “Do you return the database entity as JSON?” Strongest answer?
- The interviewer asks: “A handler throws. What does the client see?” Strongest answer?
- The interviewer asks: “How do you paginate a list endpoint?” Strongest answer?
- The interviewer asks: “Where do you validate input?” Strongest answer?
- The interviewer asks: “PUT versus PATCH?” Strongest answer?