1.3 REST APIs Flashcards

1
Q

What is an API, and why is it important?

A

An API (Application Programming Interface) is a way for two computers to talk to each other. Think of it as a messenger that takes requests from one computer (like your phone) and delivers them to another computer (like a server). The server processes the request and sends back a response. APIs are important because they allow different systems to communicate and share data, which is essential for building apps, websites, and other software.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is REST, and why is it popular?

A

REST (REpresentational State Transfer) is a set of rules or guidelines for building web APIs. It’s not a strict specification but a standard that most developers follow. REST is popular because it’s simple, easy to use, and works well over the internet. It organizes data into resources (like products or users) and uses HTTP verbs (like GET, POST, PUT, DELETE) to perform actions on those resources. Examples of RESTful APIs include Twilio, Stripe, and Google Maps.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are HTTP verbs, and how do they work in REST?

A

HTTP verbs are actions that clients can perform on resources in a RESTful API. The most common verbs are:

GET: Retrieve data about a resource (e.g., fetch a list of products).

POST: Create a new resource (e.g., add a new product).

PUT: Update an existing resource (e.g., modify a product’s details).

DELETE: Remove a resource (e.g., delete a product).
These verbs correspond to the CRUD operations: Create, Read, Update, and Delete.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are URIs in REST, and how are they used?

A

In REST, URIs (Uniform Resource Identifiers) are unique addresses used to identify resources on a server. For example, /products could be a URI for accessing a list of products, and /products/123 could be a URI for accessing a specific product with ID 123. URIs should be grouped by nouns (like /products) rather than verbs (like /getAllProducts). This makes the API more intuitive and easier to use.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does CRUD stand for, and how does it relate to REST?

A

CRUD stands for Create, Read, Update, and Delete. These are the four basic operations you can perform on data in a RESTful API:

Create: Add new data (using POST).

Read: Retrieve data (using GET).

Update: Modify existing data (using PUT).

Delete: Remove data (using DELETE).
CRUD is the foundation of most RESTful APIs, as it covers the essential actions needed to manage resources.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are HTTP status codes, and why are they important?

A

HTTP status codes are three-digit numbers that tell the client what happened to their request. They are grouped into categories:

200-level codes: Success (e.g., 200 OK means the request worked).

400-level codes: Client errors (e.g., 400 Bad Request means the request was invalid).

500-level codes: Server errors (e.g., 500 Internal Server Error means something went wrong on the server).
These codes help developers understand and debug issues in their applications.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does it mean for an API to be idempotent?

A

An API is idempotent if making the same request multiple times has the same effect as making it once. For example, a GET request is idempotent because fetching data multiple times doesn’t change anything. However, a POST request is usually not idempotent because creating the same resource multiple times could lead to duplicates. Idempotency is important for retrying failed requests safely.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does it mean for REST to be stateless?

A

Statelessness means that the server doesn’t store any information about the client between requests. Each request is independent and contains all the information needed to process it. This makes RESTful APIs easy to scale because the server doesn’t need to keep track of client sessions. For example, if you request a list of products, the server doesn’t need to remember who you are—it just processes the request and sends back the data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is pagination, and why is it used in REST APIs?

A

Pagination is a technique used to split large amounts of data into smaller, manageable chunks (or pages). For example, if an API endpoint returns 1,000 products, it might split them into pages of 100 products each. Common parameters for pagination are limit (how many items per page) and offset (where to start). Pagination improves performance and makes it easier for clients to handle large datasets.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why is API versioning important, and how is it done?

A

API versioning is important because it allows developers to make changes to an API without breaking existing applications. For example, if a new version of an API introduces breaking changes, older applications can continue using the previous version until they’re ready to upgrade. A common way to version APIs is to include the version number in the URI, like /v1/products or /v2/products. This ensures backward compatibility and gives developers time to adapt to changes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are some alternatives to REST, and when might they be used?

A

While REST is the most common API standard, there are alternatives like GraphQL and gRPC:

GraphQL: Allows clients to request exactly the data they need, reducing over-fetching and under-fetching.

gRPC: A high-performance framework for communication between microservices, often used in complex systems.
These alternatives might be used when REST isn’t the best fit, such as when you need more flexibility or better performance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly