Bitpath

Lesson 1 · Unit 01

Resources

Nouns in the URL, verbs in the method, and what each method promises

12 exercisesabout 3 min

What you practise

  • Nouns in the URL, collections and items, GET, POST, PUT, PATCH and DELETE and what each promises, safe and idempotent methods

Try a question from this lesson

Pick one

A library API works, but every action is its own POST. Which redesign says the same four things using what HTTP already provides?

POST /getBook      {"id": 7}
POST /createBook   {...}
POST /updateBook   {"id": 7, ...}
POST /deleteBook   {"id": 7}

The ideas

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

Nouns in the URL, verbs in the method

A resource is a thing your API exposes: a book, an order, a user. Its URL names it. A collection (/books) holds items (/books/7).

The method says what to do with it. New kinds of things get new URLs. New actions rarely need them.

GET    /books      list the collection
POST   /books      add a book to it
GET    /books/7    read one book
PUT    /books/7    replace it
PATCH  /books/7    change part of it
DELETE /books/7    remove it

Concept

PUT replaces, PATCH edits

PUT means "make the resource at this URL exactly this". The body is the whole new state, so anything you leave out is gone.

PATCH means "apply these changes". Fields you do not mention stay as they were.

To change one field, PATCH it, or GET the resource, edit your copy and PUT all of it back.

PUT /books/7
{"title": "Dune", "year": 1965,
 "pages": 420}

PATCH /books/7
{"pages": 420}

9 more exercises in the app

  • 1× match the pairs
  • 4× multiple choice
  • 1× fill the blanks
  • 1× true or false
  • 1× type the answer
  • 1× order the lines

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy