SlideShare a Scribd company logo
1 of 21
Download to read offline
Building a RESTful API
Best Practices

The Lob Team
www.Lob.com
@Lob
When we first started at Lob, we took a look at
industry leaders in REST API design and also at
other companies with APIs to evaluate key
elements we wanted in our API. Here we will share
some of the best practices we picked up along the
way.

www.Lob.com
The best REST API designs all have some key
requirements in place that we whittled down:
1. Clearly follow HTTP specifications
http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

2. Put the developer first, strive for ease of use to
spur adoption

www.Lob.com
REST was first introduced by Roy Felding and you
can read his dissertation for even more info.

http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_
style.htm

RESTful principles are widely adopted, here are
some of the top of mind items that we kept
revisiting while creating our REST API…

www.Lob.com
Documentation

www.Lob.com
Documentation is one of the most important parts of your API. It will
be the #1 destination any developer checks before attempting an
integration method.

Provide examples of complete request and responses and even better
use examples that can be copy-pasted directly into terminal.

www.Lob.com
API Paths

www.Lob.com
API paths should clearly show a hierarchical
relationship between resources and objects.
/v1/jobs
/v1/jobs/{JOB_ID}
/v1/objects
/v1/objects/{OBJECT_ID}/
/v1/addresses
/v1/addresses/{ADDRESS_ID}
...

Separate your API into logical resources (they should be
nouns!) where the different HTTP request methods (GET,
POST, PUT, DELETE) have specific meanings.

www.Lob.com
Make your IDs easily understood and descriptive.
Since there was so many different IDs for our
different endpoints, we wanted to make sure a user
could take a cursory glance and immediately know
what the ID represented.

job_d1a62016cba4ee83
obj_2d9b85fad42f64f8
adr_575a1b720bcdd6dc

www.Lob.com
Create
Read
Update
Delete

www.Lob.com
CRUD operations should always be handled with
HTTP protocol behaviors.

www.Lob.com
API Versioning

www.Lob.com
Always version your API to make it easier to iterate
and prevent invalid request from hitting new or old
endpoints.

Over-communicate to your customers. Make sure they are
notified in advance of any changes that may affect them so
they have appropriate time to update applications accordingly.
www.Lob.com
JSON as Output

www.Lob.com
JSON responses by default.

JSON is quickly becoming the standard output for
APIs.

www.Lob.com
Prettyprint

www.Lob.com
Prettyprint by default is one of those small things but makes
your API that much easier to use. It makes it easy for
customers who are debugging to easily read data and it is
pleasant to use.

www.Lob.com
Pagination

www.Lob.com
When you have Pagination always return links for
the so the user doesn’t need to generate the links
on their own.

- "next_url": "https://api.lob.com/v1/jobs?count=2&offset=5"
- "previous_url": "https://api.lob.com/v1/jobs?count=2&offset=3"

Do not return total counts or loop through entire
databases to get the large count.

www.Lob.com
Other great resources for further reading:
Vinay Sahni's Pragmatic RESTful API
http://www.vinaysahni.com/best-practices-for-a-pragmaticrestful-api
Matt Gemmell's API Design Post
http://mattgemmell.com/2012/05/24/api-design/
API Design is UI for Developers
http://shkspr.mobi/blog/2012/03/api-design-is-ui-fordevelopers/
Apigee's API Best Practices
http://apigee.com/about/api-best-practices

www.Lob.com
Questions or Thoughts?
Tweet @Lob
support@Lob.com
www.lob.com/blog

www.Lob.com

More Related Content

Viewers also liked

Restful design principles
Restful design principlesRestful design principles
Restful design principlesGeison Goes
 
RESTful API development with Symfony2
RESTful API development with Symfony2RESTful API development with Symfony2
RESTful API development with Symfony2Taras Omelianenko
 
REST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterREST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterSachin G Kulkarni
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkBo-Yi Wu
 
Microservice Architecture JavaCro 2015
Microservice Architecture JavaCro 2015Microservice Architecture JavaCro 2015
Microservice Architecture JavaCro 2015Nenad Pecanac
 
DataPower Restful API Security
DataPower Restful API SecurityDataPower Restful API Security
DataPower Restful API SecurityJagadish Vemugunta
 
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entitySpring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entityToni Jara
 
Building REST APIs with Spring Boot and Spring Cloud
Building REST APIs with Spring Boot and Spring CloudBuilding REST APIs with Spring Boot and Spring Cloud
Building REST APIs with Spring Boot and Spring CloudKenny Bastani
 
Building a Reactive RESTful API with Akka Http & Slick
Building a Reactive RESTful API with Akka Http & SlickBuilding a Reactive RESTful API with Akka Http & Slick
Building a Reactive RESTful API with Akka Http & SlickZalando Technology
 
Education and Training for The Future Workforce
Education and Training for The Future WorkforceEducation and Training for The Future Workforce
Education and Training for The Future WorkforceWISE
 
Sales Hacker Conference San Francisco - Jason Lemkin - The 10 Key Revenue Mis...
Sales Hacker Conference San Francisco - Jason Lemkin - The 10 Key Revenue Mis...Sales Hacker Conference San Francisco - Jason Lemkin - The 10 Key Revenue Mis...
Sales Hacker Conference San Francisco - Jason Lemkin - The 10 Key Revenue Mis...Sales Hacker
 
Charity Business Automation
Charity Business AutomationCharity Business Automation
Charity Business AutomationMohamed Shaaban
 
In sight telepsychiatry competitor profiles tracey fu
In sight telepsychiatry competitor profiles tracey fuIn sight telepsychiatry competitor profiles tracey fu
In sight telepsychiatry competitor profiles tracey futraceyxfu
 
HCLT Whitepaper: Multi- Tenancy on Private Cloud
HCLT Whitepaper: Multi- Tenancy on Private CloudHCLT Whitepaper: Multi- Tenancy on Private Cloud
HCLT Whitepaper: Multi- Tenancy on Private CloudHCL Technologies
 
A RESTful API for Controlling Dynamic Streaming Topologies
A RESTful API for Controlling Dynamic Streaming TopologiesA RESTful API for Controlling Dynamic Streaming Topologies
A RESTful API for Controlling Dynamic Streaming TopologiesMasiar Babazadeh
 
Best Practices for API Adoption
Best Practices for API AdoptionBest Practices for API Adoption
Best Practices for API AdoptionAnyPresence
 

Viewers also liked (18)

Restful design principles
Restful design principlesRestful design principles
Restful design principles
 
RESTful API development with Symfony2
RESTful API development with Symfony2RESTful API development with Symfony2
RESTful API development with Symfony2
 
REST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterREST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in Codeigniter
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP Framework
 
Microservice Architecture JavaCro 2015
Microservice Architecture JavaCro 2015Microservice Architecture JavaCro 2015
Microservice Architecture JavaCro 2015
 
DataPower Restful API Security
DataPower Restful API SecurityDataPower Restful API Security
DataPower Restful API Security
 
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entitySpring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
 
Building REST APIs with Spring Boot and Spring Cloud
Building REST APIs with Spring Boot and Spring CloudBuilding REST APIs with Spring Boot and Spring Cloud
Building REST APIs with Spring Boot and Spring Cloud
 
Building a Reactive RESTful API with Akka Http & Slick
Building a Reactive RESTful API with Akka Http & SlickBuilding a Reactive RESTful API with Akka Http & Slick
Building a Reactive RESTful API with Akka Http & Slick
 
Education and Training for The Future Workforce
Education and Training for The Future WorkforceEducation and Training for The Future Workforce
Education and Training for The Future Workforce
 
China air conditioner market report
China air conditioner market reportChina air conditioner market report
China air conditioner market report
 
Sales Hacker Conference San Francisco - Jason Lemkin - The 10 Key Revenue Mis...
Sales Hacker Conference San Francisco - Jason Lemkin - The 10 Key Revenue Mis...Sales Hacker Conference San Francisco - Jason Lemkin - The 10 Key Revenue Mis...
Sales Hacker Conference San Francisco - Jason Lemkin - The 10 Key Revenue Mis...
 
Charity Business Automation
Charity Business AutomationCharity Business Automation
Charity Business Automation
 
In sight telepsychiatry competitor profiles tracey fu
In sight telepsychiatry competitor profiles tracey fuIn sight telepsychiatry competitor profiles tracey fu
In sight telepsychiatry competitor profiles tracey fu
 
HCLT Whitepaper: Multi- Tenancy on Private Cloud
HCLT Whitepaper: Multi- Tenancy on Private CloudHCLT Whitepaper: Multi- Tenancy on Private Cloud
HCLT Whitepaper: Multi- Tenancy on Private Cloud
 
A RESTful API for Controlling Dynamic Streaming Topologies
A RESTful API for Controlling Dynamic Streaming TopologiesA RESTful API for Controlling Dynamic Streaming Topologies
A RESTful API for Controlling Dynamic Streaming Topologies
 
APIs and Innovation
APIs and InnovationAPIs and Innovation
APIs and Innovation
 
Best Practices for API Adoption
Best Practices for API AdoptionBest Practices for API Adoption
Best Practices for API Adoption
 

Recently uploaded

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 

Recently uploaded (20)

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

Building a RESTful API

  • 1. Building a RESTful API Best Practices The Lob Team www.Lob.com @Lob
  • 2. When we first started at Lob, we took a look at industry leaders in REST API design and also at other companies with APIs to evaluate key elements we wanted in our API. Here we will share some of the best practices we picked up along the way. www.Lob.com
  • 3. The best REST API designs all have some key requirements in place that we whittled down: 1. Clearly follow HTTP specifications http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html 2. Put the developer first, strive for ease of use to spur adoption www.Lob.com
  • 4. REST was first introduced by Roy Felding and you can read his dissertation for even more info. http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_ style.htm RESTful principles are widely adopted, here are some of the top of mind items that we kept revisiting while creating our REST API… www.Lob.com
  • 6. Documentation is one of the most important parts of your API. It will be the #1 destination any developer checks before attempting an integration method. Provide examples of complete request and responses and even better use examples that can be copy-pasted directly into terminal. www.Lob.com
  • 8. API paths should clearly show a hierarchical relationship between resources and objects. /v1/jobs /v1/jobs/{JOB_ID} /v1/objects /v1/objects/{OBJECT_ID}/ /v1/addresses /v1/addresses/{ADDRESS_ID} ... Separate your API into logical resources (they should be nouns!) where the different HTTP request methods (GET, POST, PUT, DELETE) have specific meanings. www.Lob.com
  • 9. Make your IDs easily understood and descriptive. Since there was so many different IDs for our different endpoints, we wanted to make sure a user could take a cursory glance and immediately know what the ID represented. job_d1a62016cba4ee83 obj_2d9b85fad42f64f8 adr_575a1b720bcdd6dc www.Lob.com
  • 11. CRUD operations should always be handled with HTTP protocol behaviors. www.Lob.com
  • 13. Always version your API to make it easier to iterate and prevent invalid request from hitting new or old endpoints. Over-communicate to your customers. Make sure they are notified in advance of any changes that may affect them so they have appropriate time to update applications accordingly. www.Lob.com
  • 15. JSON responses by default. JSON is quickly becoming the standard output for APIs. www.Lob.com
  • 17. Prettyprint by default is one of those small things but makes your API that much easier to use. It makes it easy for customers who are debugging to easily read data and it is pleasant to use. www.Lob.com
  • 19. When you have Pagination always return links for the so the user doesn’t need to generate the links on their own. - "next_url": "https://api.lob.com/v1/jobs?count=2&offset=5" - "previous_url": "https://api.lob.com/v1/jobs?count=2&offset=3" Do not return total counts or loop through entire databases to get the large count. www.Lob.com
  • 20. Other great resources for further reading: Vinay Sahni's Pragmatic RESTful API http://www.vinaysahni.com/best-practices-for-a-pragmaticrestful-api Matt Gemmell's API Design Post http://mattgemmell.com/2012/05/24/api-design/ API Design is UI for Developers http://shkspr.mobi/blog/2012/03/api-design-is-ui-fordevelopers/ Apigee's API Best Practices http://apigee.com/about/api-best-practices www.Lob.com
  • 21. Questions or Thoughts? Tweet @Lob support@Lob.com www.lob.com/blog www.Lob.com