REST API Design for SQL developers
Upcoming SlideShare
Loading in...5
×
 

REST API Design for SQL developers

on

  • 29,230 views

RESTful API design principles for SQL programmers and API developers - by @gbrail, CTO apigee

RESTful API design principles for SQL programmers and API developers - by @gbrail, CTO apigee

Statistics

Views

Total Views
29,230
Views on SlideShare
9,725
Embed Views
19,505

Actions

Likes
6
Downloads
108
Comments
0

18 Embeds 19,505

http://blog.apigee.com 19116
https://blog.apigee.com 243
http://blog.sonoasystems.com 107
http://translate.googleusercontent.com 14
https://twitter.com 6
http://webcache.googleusercontent.com 4
https://blog.edit.apigee.net 2
http://ip52.216-86-157.static.steadfast.net 2
http://www.afterjohn.appspot.com 2
http://zmezk2.appspot.com 1
https://blog2.apigee.com 1
http://who1.2cn.in 1
http://blog.jupiter.apigee.net 1
http://ip51.216-86-157.static.steadfast.net 1
http://ip53.216-86-157.static.steadfast.net 1
http://ip54.216-86-157.static.steadfast.net 1
http://ip51.216-86-157.static.steadfastdns.net 1
http://three.rdaili.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

REST API Design for SQL developers REST API Design for SQL developers Presentation Transcript

  • REST for SQL Developerswithout (too many) wordsGreg Brail @gbrailCTO, Apigee
  • The Employees TableField Type Descriptionid integer (auto-increment, Employee ID (auto-increment primary key) column)name varchar Employee Nameaddress1 varchar First line of addressaddress2 varchar Second line of addresscity varchar Employee Citystate varchar Employee Statepostal varchar Employee ZIP codecountry varchar Employee countrysalaryband integer Salary bandsalary decimal Salary, in dollars
  • The Employees APIhttp://api.mycompany.com/v1/
  • See all the employeesselect * from employees
  • See all the employeesGET /v1/employees
  • See an Employeeselect * from employees where id=123
  • See an EmployeeGET /v1/employees/123
  • Add an Employeeinsert into employees (name, address1, city, state,country, salaryband, salary)values (Hans Employee, 123 Main Street,Anytown, IL, USA, 10, 50000.0)
  • Add an Employee: Response"id" field is pre-populated because it is an auto-increment column
  • Add an EmployeePOST /v1/employeesContent-Type: application/json{"name":"Hans Employee","address1":"123 Main Street","city":"Anytown", "state":"IL","country":"USA", "salaryband":10,"salary":50000.0}
  • Add an Employee: Response 201 Created Location: /v1/employees/123
  • Permanently Fire Himdelete from employees where id=123
  • Permanently Fire HimDELETE /v1/employees/123
  • Give Him a Raiseupdate employees set salaryband=11, salary=75000.0 where id=123
  • Give Him a RaisePOST /v1/employees/123Content-Type: "application/json"{"salaryband":11, "salary":75000.0}
  • Huh?In SQL, "update" can replace any or all fieldsIn REST, we use PUT to replace the whole record But that is not always possible or a good ideaIn REST, we should use POST for a partial update Some APIs use PATCH – a new HTTP verb that is not always supported or understood
  • Assigning the ID Manuallyinsert into employees (id, name, address1, city, state,country, salaryband, salary)values (444, Hans Employee, 123 MainStreet,Anytown, IL, USA, 10,50000.0)
  • Assigning the ID Manually PUT /v1/employees/44In REST, we use POST to create a new resource when the system assigns the name. We use PUT to either replace the whole thing or create a brand-new resource when we know the name.
  • Paginate the Resultsselect * from employees limit 10select * from employees offset 10 limit 10select * from employees offset 20 limit 10
  • Paginate the Results GET /v1/employees?limit=10 GET /v1/employees?offset=10&limit=10 GET /v1/employees?offset=20&limit=10There is no "REST standard" for limiting result sets. We think that "offset" and "limit" are great de facto query parameter standards to adopt.
  • Find an Employee by Name select * from employees where name=Hans Employee
  • Find an Employee by Name GET /v1/employees?q=Hans%20Employee"q" is often used as a "search" parameter in REST APIs with various kinds of search expressions. You can support different parameters if youd like: "salaryband=10", "state=IL", and so on
  • Dont Retrieve Everythingselect id, salaryband, salary from employees
  • Dont Retrieve Everything GET /v1/employees?fields=id,salaryband,salaryThere is no "REST standard" for using a "partial response" to return only certain fields. We think that for simple response documents having a "fields" parameter makes a lot of sense.
  • Update an Employee by Name update employees set salaryband=5, salary=25000.0 where name like Hans %Upside of SQL – you can do stuff like this easily. Downside – if you have multiple employees named "Hans" then you probably just demoted some of them.
  • Update an Employee by Name GET /v1/employees?q=HansLook at the results and figure out the ID of the one you want... POST /v1/employees/47You could always have POST take parameters to allow a SQL-like update if you wish to do this, but be careful.
  • THANKS!Feedback?@gbrailgbrail@apigee.com