Link Search Menu Expand Document

API Basic

Table of contents

HTTP request method

GET, POST, PUT, DELETE, PATCH

Query parameter

                                    value   
                                       |     
   https://example.com/students?name=john&age=17
                                 |
                              parameter name (key)  
  • Query => to search
  • Parameter => a value that you can set to refine the search
  • Part of the url
  • Used to pass data
  • Typically optional
  • The API dictates th name of the parameters

Path parameter

  • Path => the location of the resource
  • Parameter => a value that you can set (variable)

Postman example

  • URL: GET http://example.com/people/john/lists.json

  • Path variables: :username => parsing john

  • Postman GET: http://example.com/people/:username/lists.json

postman-get-path-variable

HTTP cookies header

  • Cookies are rarely used for APIs
  • Cookies are used to store small amounts of data on the client’s computer
  • Cookies are sent as headers
  • The response may contain a header SET-cookie
  • The request may contain a header cookie

API documentation

Swagger 
github jobs API
Yelp
Twitter API 
Google Image search API 

REST Structure

REST stands for:

  • Representation
  • State
  • Transfer

Software architectural style:

  • No official standard
  • REST defines a set of architectural constraints
  • Many API calls themselves “REST” without actual respecting all constraints.

CURD

  • Create
  • Read
  • Update
  • Delete

Resource & Resource Identifiers

http://example.com/orders 
http://example.com/orders/[93246] --> **unique identifier**  
http://exmaple.com/[customers/84652/orders] --> **endpoint**

What is JSON?

JavaScript Object Notation, example format:

    {
        "KEY": "VALUE",
        "firstName": "John",
        "age": 29,
        "hobbies": ["netflix", "biking", "so on"], 
        "nested Json Format": {
            "phone": 123456, 
            "email": "example"
        }
    }
  • Test out using httpbin.org
curl -X POST http://httpbin.org/anything --data {"user":"john"}