API Format: The Data Formats APIs Use for Requests and Responses

API format is the way data is arranged in a request and a response. For web APIs today the default is JSON.

An API, or application programming interface, is a contract between two programs. The format is the part of that contract that says how the data looks on the wire. Both sides must agree, or the receiver cannot read the message.

If a question asks which format web APIs commonly use to return data, the answer is JSON. XML is the older alternative and is still common in enterprise and SOAP services.

The format is announced in a header. The sender sets Content-Type to say what it sent. The caller sets Accept to say what it wants back.

The common API data formats

FormatContent-TypeWhere it is used
JSONapplication/jsonMost REST and GraphQL APIs
XMLapplication/xmlSOAP services, older enterprise systems
Form dataapplication/x-www-form-urlencodedHTML form posts, some OAuth token calls
Multipartmultipart/form-dataFile uploads mixed with fields
Plain texttext/plainSimple health checks and logs
CSVtext/csvBulk report and export endpoints
Protocol Buffersbinary, used by gRPCFast internal service to service calls
YAMLapplication/yamlAPI specification files, not usually payloads

JSON wins because it is short, readable by a person, and parsed natively by JavaScript. XML carries more structure, such as namespaces and schemas, at the cost of size.

The shape of a request and a response

Format also covers the whole envelope, not only the body. A request has four parts.

  • Method. GET, POST, PUT, PATCH or DELETE, which states the action.
  • Path. The resource being addressed, such as /v1/users.
  • Headers. Content type, accepted type, authentication and version.
  • Body. The payload, which GET requests usually leave empty.

A JSON request looks like this.

POST /v1/users HTTP/1.1 Host: api.example.com Content-Type: application/json Accept: application/json { "name": "Ana Silva", "email": "ana@example.com" }

The response carries a status code, headers and its own body.

HTTP/1.1 201 Created Content-Type: application/json { "id": 1042, "name": "Ana Silva", "email": "ana@example.com" }

The same record in XML is longer and uses nested tags.

<user> <id>1042</id> <name>Ana Silva</name> <email>ana@example.com</email> </user>

The error format matters as much as the success format

Many APIs define a careful success body and then return raw text on failure. That forces every caller to guess.

Pick one error shape and use it everywhere. A useful one has a machine readable code, a human readable message, and an identifier for the failed request.

{ "error": { "code": "invalid_email", "message": "The email address is not valid.", "requestId": "b71f2c9a" } }

Match the HTTP status code to the body. A 400 means the caller sent something wrong. A 500 means the service failed.

How to choose a format

Most of the time you do not choose. You use JSON because your callers expect it.

  • Public web API. Use JSON. It is the safest default for outside developers.
  • Internal service to service traffic. Protocol Buffers over gRPC is smaller and faster.
  • File upload. Use multipart/form-data, since JSON handles binary data poorly.
  • Legacy or regulated systems. XML with a schema may be required by the other side.
  • Bulk export. CSV is still the format most data teams can consume.

How to Prepare

TAGS
System Design Interview
CONTRIBUTOR
Arslan Ahmad
Arslan Ahmad
ex-FAANG engineering manager and author or Grokking series.

GET YOUR FREE

Coding Questions Catalog

Design Gurus Newsletter - Latest from our Blog
Boost your coding skills with our essential coding questions catalog.
Take a step towards a better tech career now!
Explore Answers
What to Expect in the LangChain System Design Interview
The two half format of LangChain's 60 minute design round, the observability questions candidates report, and a walkthrough of a metric alarm system.
What is RDBMS?
What Is AWS Programming? Languages, SDKs, CLI, and Lambda
AWS is not a programming language. AWS programming means controlling Amazon Web Services from code, through an SDK, the command line, infrastructure templates, or Lambda functions, in a language you already know.
What to Expect in the AMD System Design Interview
AMD design rounds test low-level design at the hardware-software boundary: allocators, ring buffers, drivers, and GPU software stacks, often with real C++ code.
What is the entry level package of Cisco?
What is the minimum salary for software engineer in UK?
Related Courses
New
Grokking the AI System Design Interview course cover
Grokking the AI System Design Interview
Learn to design AI systems the way interviewers expect: classic ML products, LLM and RAG architectures, and agentic systems, all through the lens of the system design interview.
4.6
(3,192 learners)
Discounted price for Your Region

$98

Grokking the Coding Interview: Patterns for Coding Questions course cover
Grokking the Coding Interview: Patterns for Coding Questions
The 24 essential patterns behind every coding interview question. Available in Java, Python, JavaScript, C++, C#, and Go. The most comprehensive coding interview course with 543 lessons. A smarter alternative to grinding LeetCode.
4.6
Discounted price for Your Region

$197

Grokking Modern AI Fundamentals course cover
Grokking Modern AI Fundamentals
Master the fundamentals of AI today to lead the tech revolution of tomorrow.
4.1
Discounted price for Your Region

$72

Design Gurus logo
One-Stop Portal For Tech Interviews.
About Us
Our Team
Careers
Partners
Contact Us
Become Affiliate
Copyright © 2026 Design Gurus, LLC. All rights reserved.