Fireship · @fireship

RESTful APIs in 100 Seconds // Build an API from Scratch with Node.js Express

Uploaded February 19, 2021 · Length 11:20

RESTful APIs in 100 Seconds // Build an API from Scratch with Node.js Express

Summary

Learn how to build a RESTful API from scratch using Node.js and Express in 100 seconds.

  • restful api
  • node js
  • express
  • api development
  • javascript
  • web development

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    an application programming interface or

  2. 0:02

    api is a way for two computers to talk

  3. 0:05

    to each other using an api is just like

  4. 0:07

    using a website in your browser but

  5. 0:09

    instead of clicking buttons and filling

  6. 0:11

    out forms you write code to explicitly

  7. 0:13

    request data from a server for example

  8. 0:16

    we could visit the nasa website to look

  9. 0:18

    at asteroids or we could use their rest

  10. 0:20

    api to request the raw json data that is

  11. 0:23

    shown on the screen now most apis in the

  12. 0:25

    world are restful which means they

  13. 0:27

    follow a set of rules or constraints

  14. 0:29

    known as representational state transfer

  15. 0:31

    which has been the de facto standard for

  16. 0:33

    api development since the early 2000s a

  17. 0:36

    restful api organizes data entities or

  18. 0:39

    resources into a bunch of unique urls

  19. 0:41

    well technically not urls but uris or

  20. 0:44

    uniform resource identifiers that

  21. 0:46

    differentiate different types of data

  22. 0:48

    resources on a server a client can get

  23. 0:51

    data about a resource by making a

  24. 0:53

    request to that endpoint over http the

  25. 0:56

    request message has a very specific

  26. 0:58

    format most importantly the start line

  27. 1:00

    contains the uri that you wish to access

  28. 1:02

    which is preceded by an http verb or

  29. 1:05

    request method which signal your intent

  30. 1:07

    with the resource a get request means

  31. 1:09

    you just want to read the data while

  32. 1:11

    post means you want to create a new

  33. 1:12

    resource patch is for updates delete is

  34. 1:15

    for removing data along with a few other

  35. 1:17

    methods beyond those below the start

  36. 1:19

    line we have headers which contain

  37. 1:20

    metadata about the request the accept

  38. 1:22

    header can tell the server you want the

  39. 1:24

    data in a specific format or the

  40. 1:26

    authorization header can be used to tell

  41. 1:28

    the server that you're actually allowed

  42. 1:29

    to make that request then following the

  43. 1:31

    headers we have the body which contains

  44. 1:33

    a custom payload of data the server will

  45. 1:36

    receive the request message then execute

  46. 1:38

    some code usually to read from a

  47. 1:39

    database that can then be formatted into

  48. 1:41

    a response message the top of the

  49. 1:43

    message contains a status code to tell

  50. 1:45

    the client what happened to their

  51. 1:47

    request codes at the 200 level mean that

  52. 1:49

    things went well at the 400 level it

  53. 1:51

    means something was wrong with your

  54. 1:52

    request and at the 500 level it means

  55. 1:55

    that the server failed after the status

  56. 1:57

    code we then have the response headers

  57. 1:59

    which contain information about the