RESTful Design

Learning Objectives

By the end of this lesson, you will be able to:

- Describe what REST is and why it is important

- List the 5 HTTP verbs used in RESTful development

- Describe the HTTP methods supported by the browser

- List the CRUD RESTful routes

- Discuss CRUDL and relate it to REST concepts

- Explain how to do a PUT request in Express

- Contrast Idempotent and Safe

What is REST?

5

What are the 5 constraints of REST?

REST

REpresentational State Transfer

REST is an architectural style of APIs, where the focus is on a specific set of interactions between the client and server, rather than implementation details.

 

Its purpose is to induce performance, scalability, simplicity, modifiability, visibility, portability, and reliability.

5 Constraints

  1. Client-Server - assume a disconnected, decoupled system
  2. Stateless - A request cannot be dependent on a past request and a service treats each request independently. HTTP is a stateless protocol by design.
  3. Cacheable - assume that data received can be cached and relied upon
  4. Uniform interface - 4 additional constraints
  5. Layered System - Client can't assume a direct connection with the database

What HTTP verbs...

3

... are used in RESTFUL services

5 RESTful HTTP verbs

GET

POST

PUT

PATCH

DELETE

HTTP verbs- the Browser

HTML Forms: 'method'
- Post

- Get

 

JavaScript:

- All

HTTP, Browser & REST

How do we do a put/patch/delete?

NPM Method-Override

https://www.npmjs.com/package/method-override

What are the 5 ...

3

... RESTful CRUD routes?

5 RESTful CRUD routes

LIST

app.get('/')

READ

app.get('/:id')

CREATE

app.post('/')

UPDATE

app.patch('/:id')

app.put('/:id')

DELETE

app.delete('/:id')

Status Codes

LIST

app.get('/') : 200

READ

app.get('/:id') : 200

CREATE

app.post('/') : 201

UPDATE

app.patch('/:id') : 200

app.put('/:id') : 200

DELETE

app.delete('/:id') : 204

Idempotent 

Idempotent - A HTTP method that can be called many times without different outcomes.

Safe - A HTTP methods that do not modify resources

Learning Objectives

By the end of this lesson, you will be able to:

- Describe what REST is and why it is important

- List the 5 HTTP verbs used in RESTful development

- Describe the HTTP methods supported by the browser

- Discuss CRUDL and relate it to REST concept

- List the CRUD RESTful routes

- Explain how to do a PUT request in Express

- Contrast Idempotent and Safe

Resources

64-intro-REST

By Michelle Bergquist

64-intro-REST

Supplemental deck for a galvanize lesson

  • 530