3. How Does Your API Work? Flashcards

1
Q

What are the two parts that every HTTP request and response have?

A

The headers and the payload.

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

What is a HTTP request or response’s payload?

A

HTML, JSON, XML…

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

What range of HTTP response codes indicate that the request was successful?

A

2xx

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

What does the 2xx HTTP response code series indicate?

A

That the request was successful.

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

What does the HTTP response code 200 mean?

A

It simply means “OK.”

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

What does the HTTP response code 201 mean?

A

It means “Created.”

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

What does the HTTP response code 202 mean and what is it used for?

A

It means “Accepted.” It’s used for identifying that the action the user just performed is underway, but it’s not complete yet.

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

What does the HTTP response code 204 mean, and when is it primarily used?

A

It means “No Content.” It’s primarily used when deleting a resource.

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

What does the 3xx HTTP response code series indicate?

A

That the resource has been moved from its original URL.

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

What does the HTTP response code 301 mean?

A

It means “Moved Permanently” as in what you’re looking for is no longer available here. Most responsible APIs will then give you the URL to then retrieve it.

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

What does the HTTP response code 302 mean?

A

It means “Moved Temporarily.”

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

What does the 4xx HTTP response code series indicate?

A

That a client error has occurred.

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

What does the HTTP response code 400 mean and what does it indicate?

A

It means “Bad Request,” denoting that the most recent attempt failed due to the client itself.

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

What does the HTTP response code 401 mean and what does it indicate?

A

It means “Unauthorized,” which indicates that the required authentication credentials were not provided or the authentication has failed.

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

What does the HTTP response code 403 mean and what does it indicate?

A

It means “Forbidden,” which indicates that the user making the request is not authorized to access the API point that’s being requested.

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

What does the HTTP response code 403 mean and what does it indicate?

A

It means “Not Found,” which indicates that the resource you’re looking for does not exist.

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

What does the Content-Type HTTP header identify?

A

The type of the payload being provided by the server.

18
Q

Are you required to follow the six constraints of RESTful API?

A

No. They are not hard and fast requirements but are good design principles you should follow.

19
Q

What are the six architectural constraints of RESTful API?

A
  1. Client-Server Architecture
  2. Stateless Architecture
  3. Cacheability
  4. Idempotency
  5. Code on Demand
  6. Uniform Interfaces
20
Q

What is stateless architecture and what does it allow for each request?

A

It’s an architectural constraint of RESTful API that states that the API should be stateless. This allows each and every request to stand on its own and be processed or rejected independently of any other request in any order that they’re received.

21
Q

What is client-server architecture and what is its biggest benefit?

A

It’s an architectural constraint of RESTful API that states that the API should be designed for a client-server architecture. The biggest benefit of this is that it allows us to vary the implementation details, upgrade paths, and scalability of each independently of the other.

22
Q

What are the characteristics/benefits of a stateless architecture for HTTP requests/responses.

A
  1. Inherent to the design of the internet
  2. Stability
  3. Scalability
  4. Reliability
  5. Flexibility
23
Q

What is cacheability mean in the context of RESTful API architecture and what does it require?

A

It’s an architectural constraint of RESTful API that deals with whether a response pair can be cached. It requires that each message describes whether it can be cached and if so, for how long.

24
Q

What is the benefit of cacheability?

A

It allows the API to know when it’s possible to just return the result, instead of doing the work. This improves network performance and application usage overall.

25
Q

What does idempotency mean in the context of cacheable API requests?

A

It means that whether we execute the command 1 or N+1 times, the state of the server is exactly the same.

26
Q

What HTTP requests should we strive to make idempotent, and what ones are tricky in regards to this?

A
  1. GET, PUT, and DELETE can and should be idempotent.

2. POST is tricky. Since it can create or change the state, sometimes it’s idempotent but oftentimes it’s not.

27
Q

What do layered systems mean in the context of RESTful API architecture?

A

It means that a given component might or might not communicate with another component and that your client should not be built with the assumption that it’s communicating directly with the server. There can and often will be additional layers between the client and the server itself.

28
Q

What are the characteristics of layered systems?

A
  1. They are how the web is built
  2. Counting on direct connections/interactions adds silent, hidden dependencies, which is not the case with layered systems
  3. Allow us to add DNS lookups, load balancers, caching servers, logging, audit trails, authentication, and authorization
  4. Layers give us flexibility to improve and evolve our system as our requirements and the architecture changes.
29
Q

What is “Code on Demand” in the context of RESTful API architecture?

A

It means that a request doesn’t just retrieve a resource, but also the code to act upon it and that the client doesn’t have to know what is in the code, it just has to understand how to execute the code.

30
Q

What are the benefits of Code on Demand?

A
  1. Flexibility
  2. Upgradability
  3. Extensibility
31
Q

What are the six architectural constraints of RESTful API?

A
  1. Client-Server Architecture
  2. Stateless Architecture
  3. Cacheability
  4. Idempotency
  5. Code on Demand
  6. Uniform Interfaces
32
Q

What are the six architectural constraints of RESTful API?

A
  1. Client-Server Architecture
  2. Stateless Architecture
  3. Cacheability
  4. Idempotency
  5. Code on Demand
  6. Uniform Interfaces
33
Q

What are the six architectural constraints of RESTful API?

A
  1. Client-Server Architecture
  2. Stateless Architecture
  3. Cacheability
  4. Idempotency
  5. Code on Demand
  6. Uniform Interfaces
34
Q

What are the six architectural constraints of RESTful API?

A
  1. Client-Server Architecture
  2. Stateless Architecture
  3. Cacheability
  4. Idempotency
  5. Code on Demand
  6. Uniform Interfaces
35
Q

What are the six architectural constraints of RESTful API?

A
  1. Client-Server Architecture
  2. Stateless Architecture
  3. Cacheability
  4. Idempotency
  5. Code on Demand
  6. Uniform Interfaces
36
Q

What are the four principles that make up a uniform interface?

A
  1. Identification of resources.
  2. Manipulation of resources through these representations.
  3. Self-descriptive messages.
  4. Hypermedia as the engine of application state (HATEOAS)
37
Q

What does the “identification of resources” dictate in the context of designing uniform interfaces?

A

each resource should be uniquely addressable by a particular URL (though not a hard and fast requirement).

38
Q

What does “manipulation of resources through these representations” dictate in the context of designing uniform interfaces?

A

That every interaction with a given resource should happen through the identifier (endpoint) that we already gave it.

39
Q

What does “self-descriptive messages” dictate in the context of designing uniform interfaces?

A

That the messages should be standalone with their own processing and caching information, allowing us to create and use different types of messages very simply. This means that our client only needs to know how to retrieve and execute those instructions like the JavaScript code on demand that we see on the internet.

40
Q

What does “hypermedia as the engine of application state” dictate in the context of designing uniform interfaces?

A

HATEOAS dictates that instead of users having to go to the documentation for what’s available, each and every link must be provided to them through the API (think choose-your-own-adventure books).

41
Q

What is the biggest benefit of hypermedia as the engine of application state?

A

HATEOAS allow our apps to discover links. In effect, our apps don’t have to know every link in advance. Instead, they must know only how to discover them.