2. What Does Your API Look Like? Flashcards

1
Q

What are our resources in the context of a RESTful API design?

A

Anything anyone wants to interact with in our system. They are “nouns.”

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

What should you do if there is a “hidden” resource in the process described for a RESTful API design that you’re not really sure what it is yet?

A

Note it down and carry on with the process, and when you have the chance, ask the product owner about it.

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

Having defined your resources, what is the next logical step?

A

List out the actions that are applicable to each resource — not a complete list for the whole system, but only for the resources in question.

eg.
• List items
• List orders
• …

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

What is the HTTP method GET used for?

A

Retrieve a resource or a collection of resources.

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

What is the HTTP method DELETE used for?

A

Delete a resource.

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

What is the HTTP method PUT used for?

A

Update an existing resource.

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

What is the HTTP method POST used for?

A

Create a new resource, change the status/state of a resource, or anything else that doesn’t fit into the GET, DELETE, or PUT method.

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

What HTTP method should you use for retrieving a list of resources?

A

GET

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

What HTTP method should you use for creating a resource?

A

POST

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

What HTTP method should you use for making a link between two existing resources or modify an existing link between them?

A

PUT

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

When designing a RESTful API, what should you not do in order to not cause a huge design problem?

A

Make things up — You should always ask the product owner what they want and never make assumptions.

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

What does an independent relationship mean in the context of RESTful APIs?

A

It means that the given resource can exist on its own without any other resources.

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

What does a dependent relationship mean in the context of RESTful APIs?

A

It means that the given resource can only exist if another resource already exists.

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

What does an associative relationship mean in the context of RESTful APIs?

A

It means that the given resource can be dependent or independent but needs additional information to describe the relationship.

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

What can be said about designing an API by exposing a database schema?

A

That it’s a bad approach because fundamentally, the choices that go into designing your database are not the same choices that go into designing your API.

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

What can be said about the interaction requirements of a RESTful API and a database schema for the same application?

A

The ways that people need to interact with your API don’t necessarily map one to one with your database.

17
Q

What is the next step after having come up with the design and the structure of a RESTful API design?

A

Validate the API without wasting time, money, and effort. In other words, validate it without building it.

18
Q

What is a quick and easy way to validate an API design?

A

Write code as if the API endpoint already exists. Don’t worry about whether the code compiles or not, but instead try to figure out if the API design makes sense.

19
Q

What is the best approach to validate an API design?

A

Use a microframework and actually develop the API in a minimal way in which it accepts incoming requests, validate the corresponding verbs and URL patterns, and returns static HTTP response codes and payloads.

20
Q

What is the most common approach to validate an API design?

A

To write a documentation as if the API already existed.

21
Q

What must an API documentation include?

A
  1. List of the endpoints and descriptions of what they do
  2. List of the parameters and descriptions of what they mean
  3. List of the response codes and descriptions of when you get each
  4. Response payload examples and payload fields
22
Q

What is the goal of writing an API documentation?

A

To share it with other teams to have them accomplish their goals with our API.

23
Q

What are the two common pitfalls when writing an API documentation for API design validation?

A
  1. Most teams will want to make the documentation perfect. It should not be! Our goal must be to get feedback from other teams, partners, customers. We need a documentation that is clear and concise, but not perfect.
  2. Some people will think that documentation is the last step of a project. When people see yours, they may believe you’re almost done with the API. Make sure to tell them that the documentation is for evaluation and validation, not for indicating that the development is complete.
24
Q

What is the biggest benefit of validating an API design by writing a documentation as if it existed already?

A

The documentation is almost done. Now, as you build the API, you can make sure to keep this documentation up to date and it’s a small marginal effort, not a massive effort at the end.