User Tools

Site Tools


misc:api_building_notes

API Building Notes

Define your endpoints

  • api/v1/things ⇒ list of all things
  • api/v1/things/<id> ⇒ the thing with id of <id>
  • api/v1/things/<id>/subthings ⇒ a things's subthings
  • api/v1/thing/<id>/subthings/<id> ⇒ one of thing's subthings
  • api/v1/search?q=thing+to+search+for&foo=other+thing

Client

Send URL and METHOD.

  • GET : read
  • POST : create
  • PUT : update
  • DELETE: delete

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
misc/api_building_notes.txt · Last modified: 2016/07/15 19:10 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki