Table of Contents

API Building Notes

Define your endpoints

Client

Send URL and METHOD.

Extra data for POST and PUT is sent in headers. Query params (e.g., for search) as query params.

Server

Receive request
if URL not found
  format error message as json
  send message with code 401
  exit
route to handler

Handler:
if GET
  Get query data (if any)
  get the requested data
  format and encode as json
  send message with return code 200
else if POST
  get header data (if any)
  get query data (if any)
  create new resource (in DB or whatever)
  format and encode new resource data as json (?)
  send message with return code TODO
else if PUT
  get header data (if any)
  get query data (if any)
  get resource (from DB or whatever)
  update resource (in model)
  rewrite resource (to DB or whatever)
  format and encode new resource data as json (?)
  send message with return code TODO
else if DELETE
  get query data (if any)
  delete resource (in DB or whatever)
  format and encode (what?) as json
  send message with return code TODO
on error
  format error message as json
  send message with code TODO