What is an API?
API stands for Application Programming Interface. It’s a set of rules for how programs can talk to each other. When building web applications, APIs define how frontends can request data from backends.
You’ve already used APIs as a frontend developer with the provided Noroff APIs.
REST APIs
REST (Representational State Transfer) is a popular way to structure APIs. Most web APIs you’ll encounter use REST.
What makes an API “RESTful”?
-
Uses standard HTTP methods:
- GET: Retrieve data
- POST: Create new data
- PUT: Update existing data (replace entirely)
- PATCH: Update existing data (partial update)
- DELETE: Remove data
-
URLs represent resources (things in your system):
/users - represents all users /users/123 - represents the user with ID 123 /users/123/posts - represents all posts by user 123 -
Returns data in a consistent format (usually JSON):
{ "id": 123, "name": "Sarah Chen", "email": "sarah@example.com" } -
Stateless - each request stands alone. The server doesn’t remember anything between requests. Each request must contain all the information needed to understand and process it.
Practical REST Examples:
GET /products - Get all products
GET /products/456 - Get product with ID 456
POST /products - Create a new product
PUT /products/456 - Update product 456
DELETE /products/456 - Delete product 456
Why REST is Popular
- Works with standard HTTP (no special protocols)
- Simple to understand and implement
- Supported by all programming languages
- Easy to test with browser tools
Other API Patterns
While REST is the most common, you might encounter other API patterns:
- GraphQL: Lets clients request exactly what data they need in a single request
- SOAP: Older XML-based protocol, more complex and less common now
- WebSockets: For real-time, two-way communication (chat apps, live score updates)
We’ll focus on REST as it’s the most common and straightforward for building APIs.