Making HTTP Requests


API basics

API basics

To delete: get a patch to put on the post

REST APIs uses common HTTP methods

  • 39 HTTP methods exist
  • 5 HTTP methods typically used in APIs, corresponding to the CRUD principle
    • CRUD = Create Read Update Delete

  • GET: retrieves information (without changing the information)
  • POST: creates new information (based on the values passed to the API)
  • PUT: updates information
  • PATCH: updates information
  • DELETE: deletes information
    CRUD

PUT vs. PATCH

PUT and PATCH are both used to update information, but there’s a big difference!

PUT is a method that updates the entire resource (= record / object)
→ it overwrites the entire existing resource

PATCH is a method that updates a portion of the resource
→ it only updates the fields/attributes you send to the API

Endpoints and parameters

API endpoint = digital location where requests are sent to (server side)
APIs usually have multiple endpoints

To address an endpoint, the client must provide:

  • A Uniform Resource Locator (URL)
  • A method (GET, POST, …)
  • A list of headers
    • Provides metadata about the request
  • A body
    • Contains the data sent by the client to the server
    • Not every request contains a body

Address endpoint

API parameters: options that can be passed with the endpoint
Goal: influence the endpoint's response → filtering
Added by adding a question mark (?) after the endpoint, followed by the parameter name, an equal sign (=) and the parameter value

Syntax: https://www.myapi.com/endpoint?parametername=parametervalueopen in new window

Multiple parameters can be passed if necessary
Parameters are separated by an ampersand (&)

Syntax: https://www.myapi.com/endpoint?first=firstvalue&second=secondvalueopen in new window

Address endpoint with 1 parameter

Try it out!

Go to https://v2.jokeapi.dev/open in new window and scroll down to the section 'Try it out here'
Try out some of the options and watch how it influences the full URL
Copy the link and make a GET request from Postman

Joke API

Last update: 9/16/2022, 7:24:59 PM