HomeToolsAbout

Intro to API

What is API

Application Programming Interface

  • Way for two machines to each other
    • Used to explicitly request data from server

RESTFul Standard

Organizes data entities (resources) to unique URIs in the server

  • Making a request to the specific endpoint
    • Request is specific (HTTP verb)

URI stands for uniform resource identifiers

Rules to be Restful

Client-Server Architecture

  • Separation of Concerns
  • RESTful API should not care about the UI

Stateless

  • No client-context is store in the server

Cacheability

  • Responses must define themselves as cacheable or non-cacheable (to the client)

Layered System

  • Intermediate servers may be used without the client knowing about it

Uniform Interface

  • Resources are identified in Requests, transferred data is decoupled from DB schema
  • Self-descriptive messages links to further resources

Anatomy

Headers = Metadata about the request Body = Payload of data

Server will execute the code from request and form a response

  • Response come with status code

Response Header

  • Status about the server

Stateless

  • Two parties don't store info about each other
  • Every req-res is independent from all other cycles

Set of commands, functions, protocols, and objects that programmers can use to create software or interact with an external system

  • Provides developers standard commands for performing common operations so they do not have to write the code from scratch

Endpoint

Endpoint is a url to a specific api resource

# endpoint examples /this-is-an-endpoint /another/endpoint /some/other/endpoint /login /accounts /cart/items # full URL example https://example.com/this-is-an-endpoint https://example.com/another/endpoint https://example.com/some/other/endpoint https://example.com/login https://example.com/accounts https://example.com/cart/items

Trailing slash

Caches will store trailing stashes as separate items.

http://example/foo http://example/foo/

Most APIs do not end with a trailing slash.

Contrary to arguments, a collection should be named using a plural.

  • In this sense, trailing slash is unnecessary in any case.

HTTP Methods

Different HTTP methods will result in different results even on the same endpoint.

GET /item/{id} PUT /item/{id}
  • GET for retrieving (as in "cRud" abbreviation)
  • PUT for updating (as in "crUd")

Interview questions related to API

  • Describe recent APIs designed or worked with (give examples)
  • How do you address throttling to ensure a RESTful API performs well under spikes in calls?
    • rate limiting
    • IP-level whitelist
    • concurrent connection limit
      • limit users and save services to reduce spike
    • resource-level limit
      • limit users from specific resources
  • How to secure REST API
    • HTTPS
    • Hashing - important properties should be hashed
    • Never expose param in URL
    • OAuth to protect routes
AboutContact