6.5 REST-based APIs Flashcards

Summarize characteristics of REST-based APIs (authentication types, CRUD, HTTP verbs, and data encoding). (33 cards)

1
Q

Define:

API Key

A

A unique identifier used to authenticate API requests.

API keys are commonly used to control access to public or private resources, and they help in tracking API usage.

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

What is a RESTful API?

A

An interface using HTTP requests to perform CRUD operations.

REST stands for Representational State Transfer, emphasizing statelessness and a uniform interface.

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

Define:

“statelessness” in RESTful APIs.

A

Each request must contain all required information.

The server doesn’t store session data, making the system scalable and easy to manage.

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

What are the six attributes defined for REST APIs?

A
  1. Client/server architecture
  2. Stateless operation
  3. Clear statement of cacheable/uncacheable
  4. Uniform interface
  5. Layered
  6. Code-on-demand

Client/server architecture: Separation of client and server roles.

Stateless operation: Each request is independent and has all necessary information.

Clear statement of cacheable/uncacheable: Specifies which responses can be cached.

Uniform interface: Consistent interface for interaction across services.

Layered: Allows multiple layers of servers between client and server.

Code-on-demand: Server can provide executable code to the client.

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

True or False:

REST APIs are always stateless.

A

True

Statelessness means the server doesn’t retain client session information between requests.

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

Describe the concept of a resource in RESTful APIs.

A

It is any object or data accessed via a URI.

Resources can represent users, documents, or any entity that can be acted upon by HTTP methods.

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

List two required attributes of a REST-based API.

A
  1. Uses HTTP
  2. Client/server architecture

Uses HTTP: RESTful APIs rely on the HTTP protocol for communication.

Client/server architecture: RESTful APIs maintain a clear separation between client and server.

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

List the four primary HTTP methods used in REST APIs.

A
  1. GET
  2. POST
  3. PUT
  4. DELETE

GET: Retrieves data from the server without modifying any resource.

POST: Sends data to the server to create a new resource.

PUT: Updates an existing resource with new data.

DELETE: Removes a specified resource from the server.

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

Why are HTTP verbs important in REST APIs?

A

They define the action on resources.

HTTP verbs play a crucial role in REST APIs by standardizing how clients interact with resources.

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

How does the GET method work in REST APIs?

A

It retrieves data without modifying the resource.

GET is used to fetch data like user details or product information from the server.

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

What are the four fundamental operations that a REST API can perform?

A
  • Create
  • Read
  • Update
  • Delete

Create: Adds new resources to the server.

Read: Retrieves existing resources from the server.

Update: Modifies existing resources on the server.

Delete: Removes resources from the server.

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

True or False:

The DELETE method permanently removes a resource from the server.

A

True

DELETE is used to permanently delete the specified resource.

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

Which HTTP verb corresponds to the CRUD action ‘Read’?

A

GET

The GET method is used to retrieve data from the server without modifying any resource. It is the standard method for reading data in RESTful APIs.

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

True or False:

PUT and PATCH can be used interchangeably to update a resource.

A

False

PUT replaces the entire resource, while PATCH updates only the specified fields.

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

What type of architecture do REST APIs use?

A

Client/server

Clients handle user interactions, while servers manage data storage and processing.

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

Fill in the blank:

The HTTP verb used for updating an existing resource is ______.

A

PUT

PUT replaces an existing resource with a new version.

17
Q

Describe how the PATCH method works in REST APIs.

A

It partially updates a resource.

PATCH is used to apply updates to specific fields, unlike PUT which replaces the entire resource.

18
Q

Fill in the blank:

The HTTP verb for creating new data structures is ______.

A

POST

POST is used to create new resources on the server.

19
Q

Describe the role of authentication in REST APIs.

A

It ensures only authorized access to resources.

Common methods include Basic Authentication, OAuth, and API keys for securing API endpoints.

20
Q

Define:

Basic Authentication

in REST APIs

A

A method where the client sends base64-encoded credentials.

While easy to implement, it is considered insecure because the credentials can be easily decoded if intercepted. It’s often recommended to use it over HTTPS or opt for more secure authentication methods like OAuth.

21
Q

How does OAuth work as an authentication method in REST APIs?

A

It uses tokens to grant access without exposing credentials.

OAuth allows secure and delegated access to resources without sharing passwords.

22
Q

Why is data encoding important in REST APIs?

A

It ensures proper data transmission.

It maintains data integrity and supports content negotiation, allowing clients and servers to agree upon the data format (such as JSON or XML) for communication.

23
Q

What is the most commonly used data format in REST APIs?

A

JSON

(JavaScript Object Notation)

JSON is lightweight, easy to read, and supported by most web technologies.

24
Q

What type of data does a REST API typically return?

A

In text format, commonly as JSON.

REST APIs primarily return data in textual formats like JSON (JavaScript Object Notation) due to its lightweight nature and ease of use.

25
# True or False: A RESTful API **always** uses JSON as its data format.
False ## Footnote While JSON is common, REST APIs can also use *XML, HTML, or other formats.*
26
Why is XML **still used** in some REST APIs despite JSON's popularity?
It supports **more complex** data structures and attributes. ## Footnote **XML (eXtensible Markup Language)** offers *features* like a rich set of data types, support for namespaces, and a strict schema definition, which can be beneficial for representing complex data structures and ensuring data integrity.
27
Describe the **role** of HTTP headers in REST APIs.
They carry metadata like **authentication** and **content-type**. ## Footnote **Headers** ensure that the server understands the request and responds accordingly.
28
What is the **purpose** of URIs in REST APIs?
They **identify the specific resource** that the HTTP request acts on. ## Footnote **URIs (Uniform Resource Identifiers)** direct API requests to the correct resource for processing.
29
Describe the **structure** of a URI used in a REST API call.
It **includes** the protocol, hostname/IP address, path (resource), and query parameters. ## Footnote The **URI** is crucial for routing API requests to the correct resource.
30
How does **error handling** work in REST APIs?
REST APIs use **HTTP status codes** to indicate the result of an API request. ## Footnote *Status codes* such as 400 (Bad Request), 401 (Unauthorized), and 500 (Internal Server Error) help clients understand how the request was processed.
31
# True or False: REST APIs **always return** a 200 status code for successful operations.
False ## Footnote *Different HTTP status codes* (like 201, 204, etc.) may be used to indicate success or the type of operation (e.g., creation, no content).
32
What does the HTTP status code 404 **indicate** in a REST API response?
Not Found ## Footnote A *404 status code* means the requested resource could not be found on the server.
33
How does **"Token-based Authentication"** work in REST APIs?
It uses tokens (e.g., JWT) to **authenticate** users. ## Footnote Token-based authentication *enhances security* by **avoiding** the need to transmit sensitive credentials and allows for single sign-on (SSO) across applications.