====== API Building Notes ====== ===== Define your endpoints ===== * ''api/v1/things'' => list of all things * ''api/v1/things/'' => the thing with id of * ''api/v1/things//subthings'' => a things's subthings * ''api/v1/thing//subthings/'' => 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