Learning REST APIs Flashcards

Learn the basics of REST APIs. Discover what they are, why they matter, and how putting REST APIs to use can help you build faster, more efficient applications.

1
Q

What does REST stand for

A

Representational State Transfer

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

What does API stand for

A

Application Programing Interface

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

What is REST?

A

Representational State Transfer refers to a group of software architecture design constraints that bring about efficient, reliable, and scalable systems

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

A representational state is transferred as a ____ which means the website doesn’t have to reload the whole page

A

Data Object (As opposed to having to load the new pages whole set of HTML Code)

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

What is an API

A

A set of features and rules that exist inside a software program enabling interaction between the software and other items, such as other software or hardware

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

what is the collection of tools used to access and work with REST resources?

A

API (Application Programming Interface)

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

What does URI stand for?

A

Universal Resource Identifier

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

What is a URI?

A

“A compact sequence of characters that identifies an abstract or physical resource” that “provides a simple and extensible means for identifying a resource”

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

What is the most generic way to name and locate a web resource?

A

URI?

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

What does URL Stand for?

A

Subset of the URI that identifies a resource and explains how to access that resource (https:// or ftp://)

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

What does URN stand for?

A

Universal Resource Name

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

What is a URN? How is that different from a URL?

A

Its the unique name of a URI. The URL includes the location which is not part of the URN.

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

What are the Six Constraints of REST

A
  1. Client - server architecture
  2. Statelessness
  3. Cacheability
  4. Layered system
  5. Code on demand
  6. Uniform interface
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

REST Constraint: Client - server architecture

A

This constraint ensures proper separation of concerns. The client manages user interface concerns while the server manages data storage concerns

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

REST Constraint: Statelessness

A

No client context or information, aka “state”, can be stored on the server between requests.

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

REST Constraint: Cacheability

A

All REST responses must be clearly marked as cacheable or not cacheable

17
Q

REST Constraint: Layered system

A

The client cannot know, and shouldn’t care, whether it’s connected directly to the server or to an intermediary like a CDN or mirror

18
Q

REST Constraint: Code on demand

A

Servers are allowed to transfer executable code like JavaScript and compiled components to clients

19
Q

REST Constraint: Uniform interface

A

6.1 Resource identification in request
The URI request must specify what resource it is looking for and what format the response should use

6.2 Resource manipulation through representations
Once a client has a representation of a resource, it can modify or delete the resource

6.3 Self-descriptive messages
Self descriptive messages (messages must identify their format so they can be parsed

6.4 Hypermedia as the engine of application state
Once a client has access to a REST service, it should be able to discover all available resources and methods through the hyperlinks provided

20
Q

who are the clients that consume the REST API?

A

This is the website or app that sends the request and parses the response

21
Q

What is reqres.in?

A

This is a website that allows REST messages to be sent and will return data in order to allow users to test

22
Q

What is a “resource” in REST

A

Any information that can be named can be a resource such as a document or image, a temporal service, a collection of other resources, a non-virtual object and so on

23
Q

what does a REST server generate for clients upon request?

A

A representation of the requested resource. This allows multiple clients to access the same data at the same time

24
Q

what are HTTP methods?

A

These are the commands (verbs) used to interact with the server. Such as using GET to retrieve information from the resource

25
Q

What are the three methods to send data to the resource from the client?

A

POST - Create a new resource and add it to a collection on the target site

PUT - used to update all data for a “singleton” resource based on ID by replacing all existing content

PATCH - Used to modify an existing singleton resource without replacing everything

26
Q

What are the return codes for a POST method?

A

201 - created
401 - unauthorized
409 - conflict (resource already exists)
404 - not found (if it’s sent to a resource that doesn’t exist)

27
Q

what are the return codes for a PUT method

A

200 OK
401 - Unauthorized
404 - Not Found
405 - Method not allowed (when sent to a collection resource, since PUT can only update a singleton resource)

28
Q

What are the return codes for a PATCH method

A

200 OK
401 - Unauthorized
404 - Not Found
405 - Method not allowed (when sent to a collection resource, since PATCH can only update a singleton resource)

29
Q

What are the return codes for a DELETE method

A

200 - OK
401 - Unauthorized
404 - Not Found

405 - Method not allowed (Can only be used with Singleton resources!)

30
Q

What are the OPTIONS and HEAD methods for?

A

Options returns a description of the communication options for the target resource

Head returns only the header of that response

31
Q

What will every response to a REST query contain?

A

a HEAD with information about what happened including the HTTP Status message

32
Q
What are the http response status codes in the following ranges:
100s
200s
300s
400s
500s
A
100s - Information
200s - Success
300s - Redirection
400s - Client error
500s - Server error
33
Q

What are 100s codes

A

These are informational and are rare. Generally used to say please wait for server or something of that nature

34
Q

what are 200s codes

A

These are for versions of success
200 - OK

201 - Created (new resource created)

204 - No content (server processed request but returned nothing)

35
Q

What are the 300s codes

A

These are forms of redirection
301 - Moved permanently (gives the new URI for future requests)

302/303 - Found at this other URL

307 - Temporary redirect

308 - Resume incomplete

36
Q

What are the 400s codes

A

These are forms of Client errors
400 - Bad request (request is malformed or too large)

401 - Unauthorized (client lacks authentication)

403 - Forbidden (outright refused, maybe client isn’t logged in)

404 - Not found (resource does not exist at all)

405 - Method not allowed (used when a method is used that isn’t compatible with the resource being accessed)

37
Q

What are the 500s codes

A

These are forms of Server errors
500 - Internal server error

502 - Bad gateway (received invalid response)

503 - Service unavailable (server is overloaded or temporarily unavailable)

38
Q

when sending a REST request which methods are available for the target resource can be changed by adding what to the request?

A

Adding authentication such as line 2 in the following example:

  1. HEAD http://restful.dev/wp-json/wp/v2/posts
  2. Authorization: Basic andmbowe password
39
Q

What is needed (after the URI and authorization) to POST something to a resource?

A

a content type to describe the type of data that will be sent (line 3) and the data itself (line 4+)

  1. HEAD http://restful.dev/wp-json/wp/v2/posts
  2. Authorization: Basic andmbowe password
  3. Content-Type: application/json
  4. {
  5. “title”: “A post created via the REST API!”,
  6. “content”: “abc123”
  7. “Status”: “publish”, (it would be in draft without this)
  8. “author”: 1
  9. }