SlideShare a Scribd company logo
© 2016 SecurityMetrics
without losing too much sleep
Creating a RESTful API
Mike Anderson
Chief Architect – Software Development
mmandersonii@securitymetrics.com
ABOUT SECURITYMETRICS
Helping organizations comply
with mandates, avoid security
breaches, and recover from data
theft since 2000
What is REST
• REpresentational State Transfer
– An application should be able to “browse” your api by knowing
a starting place (a bookmark)
– When data is returned from a particular call, available
“transfers” are included in the response (REpresentation) as
links with data types
• Roy Fielding’s Doctoral Dissertation, primarily chapter 5
http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_a
rch_style.htm
Data + Hypermedia
• HATEOAS - Hypermedia As The Engine Of Application State
– One of the driving forces behind REST.
– The “Transfer” part of REST
Structuring your code
• Layer your code into
– Endpoints
– Services
– Data
• If the language you are using supports interfaces, use
them to allow you to swap in different implementations
for different situations
– testing
Structuring your code?page=2
DB
Data Layer (ORM)
Service Layer (Business logic)
REST Layer (endpoint)
Test Automation
Test Automation
Test Automation
Testing
• Unit testing
– Only test the method under test for logic errors.
• Functional testing
– Test through multiple layers
• Integration testing
– Test across multiple services
Data formats
• Content-Type and Accept headers
– Content-Type: what is the format of the data are you
expecting for input
– Accept: what is the format of the data will you be returning
• Typical data types
– JSON - Pretty much the current standard, especially for
consumption by JavaScript
– XML - Earlier standard. More restrictive format and verbosity
– CSV - Useful for data import and export
Security
• Closed by default
– Build it in at the beginning, don’t tack it on at the end
– Allows for “safer”, more reliable releases. If authentication
and authorization are built in you can provide releases to
authorized users without exposing sensitive data
Documentation
• Interactive documentation is very helpful
• If it can be generated from/by the code it is more likely to
stay up to date
• Try and use a standard like the OpenAPI Specification
– See http://swagger.io/
– You can define the contract for your api with its associated
documentation, generate the base endpoints for different
languages and generate test cases to validate your
implementation
– Good tutorial at https://github.com/tylerdave/OpenAPI-Tutorial/
Resource naming
• Two primary URLs for a given resource
– /resources - a collection of resources
– /resources/:id - a specific resource
• :id can be any identifier but it has to be unique
• uuid (Universally Unique IDentifier) is a good option
• Use plural nouns for resource names
– employees vs employee
• Use HTTP Verbs for processing
– Create = POST
– Read = GET/HEAD
– Update = PUT/PATCH
– Delete = DELETE
Versioning your API
• In the URL
• With request parameters
• Using custom headers
• Using Accept header
Versioning your API?page=2
• Depending on whom you ask, any of those ways are wrong
– https://www.troyhunt.com/your-api-versioning-is-wrong
-which-is/ - a somewhat tongue in cheek article about
this
• It’s your API
– You are defining the contract. You get to choose but make a
choice and stick with it
– What are the practical reasons for your choice?
– How do you support it in your back-end language/framework?
– How are you expecting your API to be consumed?
Collections and Pagination
• Implement pagination as early as possible. It will save
future headaches
• Use standard defaults throughout your API
– Default number of entries between 10 and 1000. Ask your
consumers (if you can) what works best for them
– You should probably have an upper limit (1000?) per request
• You want to allow for batching but too large of a dataset in a request
can slow down applications, particularly JavaScript
• Page number and number of entries are query
parameters
Collections and Pagination?page=2
• https://server.com/api/resources?page=2&items=100
• In the returned links, include links for the next,
previous, first and last pages
Caching responses
• Speeds up follow up requests for the same resource
– Some frameworks support this directly or have libraries that
support it
– Proxy servers can be configured to support it but it helps to
understand the tradeoffs
• Web standards
– ETags
• Cache busting - updating the cache when a resource
is updated
Things to avoid
• Doing everything in one method (handle inputs, query
database, transform results, handle errors, etc.)
• Raw SQL
– More of a strong guideline but raw SQL can become brittle
– Take advantage of the ORM and data models
• NOT writing tests
– When you have to change a schema/model or refactor your
code, how do you know things still work without tests?
Exercising your API
• Postman - https://www.getpostman.com/
• Allows you to test all of the different verbs
• Allows you to create collections of related requests
• You can set headers and body data for requests
• Allows you to define different environments to
parameterize requests
Postman Demo
www.securitymetrics.com
Questions?
● My email: mmandersonii@securitymetrics.com
● Slides:
https://www.slideshare.net/MikeAnderson64/creating-a-restful-api-without-
losing-too-much-sleep
www.securitymetrics.com
Thank you!
● My email: mmandersonii@securitymetrics.com
● Slides:
https://www.slideshare.net/MikeAnderson64/creating-a-restful-api-without-
losing-too-much-sleep

More Related Content

PDF
REST-API overview / concepts
PPTX
How to paas the cloud
PDF
Little rock data management 032621
PDF
Rest api design by george reese
PPTX
REST-API's for architects and managers
PDF
Implementing Site Search in CQ5 / AEM
PPTX
Super simple introduction to REST-APIs (2nd version)
PDF
Spring REST Docs: Documenting RESTful APIs using your tests - Devoxx
REST-API overview / concepts
How to paas the cloud
Little rock data management 032621
Rest api design by george reese
REST-API's for architects and managers
Implementing Site Search in CQ5 / AEM
Super simple introduction to REST-APIs (2nd version)
Spring REST Docs: Documenting RESTful APIs using your tests - Devoxx

What's hot (16)

PPTX
Introduction to REST - API
PPTX
Extending drupal authentication
PPT
Introduction to the Web API
PPTX
REST API Design & Development
PPTX
Building infrastructure with Azure Resource Manager using PowerShell
PDF
Representational State Transfer (REST)
PDF
REST API and CRUD
PPTX
Best Practices You Must Apply to Secure Your APIs - Scott Morrison, SVP & Dis...
PDF
HAL APIs and Ember Data
PPTX
Effective Searching by Dominik Kornas
PPT
Amazon s3
PPTX
EnterpriseSearch
PDF
Best Practices in Web Service Design
PPTX
Deep thoughts from the real world of azure
PPTX
REST API
PPTX
REST-API introduction for developers
Introduction to REST - API
Extending drupal authentication
Introduction to the Web API
REST API Design & Development
Building infrastructure with Azure Resource Manager using PowerShell
Representational State Transfer (REST)
REST API and CRUD
Best Practices You Must Apply to Secure Your APIs - Scott Morrison, SVP & Dis...
HAL APIs and Ember Data
Effective Searching by Dominik Kornas
Amazon s3
EnterpriseSearch
Best Practices in Web Service Design
Deep thoughts from the real world of azure
REST API
REST-API introduction for developers
Ad

Similar to Creating a RESTful api without losing too much sleep (20)

PPT
APITalkMeetupSharable
PDF
Business Applications Integration In The Cloud
PDF
Modern REST API design principles and rules.pdf
PDF
PDF
zendframework2 restful
PDF
Resting on your laurels will get you powned
PDF
Pushing Chemical Biology Through the Pipes
PDF
apidays LIVE Paris 2021 - Lessons from the API Stewardship Journey in Azure b...
PPTX
Lessons learned on the Azure API Stewardship Journey.pptx
PPTX
SharePoint 2013 - What's New
PPTX
REST != WebAPI
PDF
M meijer api management - tech-days 2015
PPTX
Restful webservice
PPTX
RESTful web APIs (build, document, manage)
PPTX
Ladies Be Architects - Integration - Multi-Org, Security, JSON, Backup & Restore
PPTX
JavaOne2013 Leveraging Linked Data and OSLC
PPTX
gRPC, GraphQL, REST - Which API Tech to use - API Conference Berlin oct 20
PDF
Role of Rest vs. Web Services and EI
PPT
ArcReady - Architecting For The Cloud
PPTX
Design a share point 2013 architecture – the basics
APITalkMeetupSharable
Business Applications Integration In The Cloud
Modern REST API design principles and rules.pdf
zendframework2 restful
Resting on your laurels will get you powned
Pushing Chemical Biology Through the Pipes
apidays LIVE Paris 2021 - Lessons from the API Stewardship Journey in Azure b...
Lessons learned on the Azure API Stewardship Journey.pptx
SharePoint 2013 - What's New
REST != WebAPI
M meijer api management - tech-days 2015
Restful webservice
RESTful web APIs (build, document, manage)
Ladies Be Architects - Integration - Multi-Org, Security, JSON, Backup & Restore
JavaOne2013 Leveraging Linked Data and OSLC
gRPC, GraphQL, REST - Which API Tech to use - API Conference Berlin oct 20
Role of Rest vs. Web Services and EI
ArcReady - Architecting For The Cloud
Design a share point 2013 architecture – the basics
Ad

Recently uploaded (20)

PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Nekopoi APK 2025 free lastest update
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Digital Strategies for Manufacturing Companies
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
ISO 45001 Occupational Health and Safety Management System
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PPTX
Online Work Permit System for Fast Permit Processing
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
System and Network Administraation Chapter 3
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
top salesforce developer skills in 2025.pdf
Which alternative to Crystal Reports is best for small or large businesses.pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Nekopoi APK 2025 free lastest update
Design an Analysis of Algorithms I-SECS-1021-03
Digital Strategies for Manufacturing Companies
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
ISO 45001 Occupational Health and Safety Management System
ManageIQ - Sprint 268 Review - Slide Deck
How to Choose the Right IT Partner for Your Business in Malaysia
PTS Company Brochure 2025 (1).pdf.......
2025 Textile ERP Trends: SAP, Odoo & Oracle
Online Work Permit System for Fast Permit Processing
How Creative Agencies Leverage Project Management Software.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Operating system designcfffgfgggggggvggggggggg
System and Network Administraation Chapter 3
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Internet Downloader Manager (IDM) Crack 6.42 Build 41
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
top salesforce developer skills in 2025.pdf

Creating a RESTful api without losing too much sleep

  • 1. © 2016 SecurityMetrics without losing too much sleep Creating a RESTful API Mike Anderson Chief Architect – Software Development mmandersonii@securitymetrics.com
  • 2. ABOUT SECURITYMETRICS Helping organizations comply with mandates, avoid security breaches, and recover from data theft since 2000
  • 3. What is REST • REpresentational State Transfer – An application should be able to “browse” your api by knowing a starting place (a bookmark) – When data is returned from a particular call, available “transfers” are included in the response (REpresentation) as links with data types • Roy Fielding’s Doctoral Dissertation, primarily chapter 5 http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_a rch_style.htm
  • 4. Data + Hypermedia • HATEOAS - Hypermedia As The Engine Of Application State – One of the driving forces behind REST. – The “Transfer” part of REST
  • 5. Structuring your code • Layer your code into – Endpoints – Services – Data • If the language you are using supports interfaces, use them to allow you to swap in different implementations for different situations – testing
  • 6. Structuring your code?page=2 DB Data Layer (ORM) Service Layer (Business logic) REST Layer (endpoint) Test Automation Test Automation Test Automation
  • 7. Testing • Unit testing – Only test the method under test for logic errors. • Functional testing – Test through multiple layers • Integration testing – Test across multiple services
  • 8. Data formats • Content-Type and Accept headers – Content-Type: what is the format of the data are you expecting for input – Accept: what is the format of the data will you be returning • Typical data types – JSON - Pretty much the current standard, especially for consumption by JavaScript – XML - Earlier standard. More restrictive format and verbosity – CSV - Useful for data import and export
  • 9. Security • Closed by default – Build it in at the beginning, don’t tack it on at the end – Allows for “safer”, more reliable releases. If authentication and authorization are built in you can provide releases to authorized users without exposing sensitive data
  • 10. Documentation • Interactive documentation is very helpful • If it can be generated from/by the code it is more likely to stay up to date • Try and use a standard like the OpenAPI Specification – See http://swagger.io/ – You can define the contract for your api with its associated documentation, generate the base endpoints for different languages and generate test cases to validate your implementation – Good tutorial at https://github.com/tylerdave/OpenAPI-Tutorial/
  • 11. Resource naming • Two primary URLs for a given resource – /resources - a collection of resources – /resources/:id - a specific resource • :id can be any identifier but it has to be unique • uuid (Universally Unique IDentifier) is a good option • Use plural nouns for resource names – employees vs employee • Use HTTP Verbs for processing – Create = POST – Read = GET/HEAD – Update = PUT/PATCH – Delete = DELETE
  • 12. Versioning your API • In the URL • With request parameters • Using custom headers • Using Accept header
  • 13. Versioning your API?page=2 • Depending on whom you ask, any of those ways are wrong – https://www.troyhunt.com/your-api-versioning-is-wrong -which-is/ - a somewhat tongue in cheek article about this • It’s your API – You are defining the contract. You get to choose but make a choice and stick with it – What are the practical reasons for your choice? – How do you support it in your back-end language/framework? – How are you expecting your API to be consumed?
  • 14. Collections and Pagination • Implement pagination as early as possible. It will save future headaches • Use standard defaults throughout your API – Default number of entries between 10 and 1000. Ask your consumers (if you can) what works best for them – You should probably have an upper limit (1000?) per request • You want to allow for batching but too large of a dataset in a request can slow down applications, particularly JavaScript • Page number and number of entries are query parameters
  • 15. Collections and Pagination?page=2 • https://server.com/api/resources?page=2&items=100 • In the returned links, include links for the next, previous, first and last pages
  • 16. Caching responses • Speeds up follow up requests for the same resource – Some frameworks support this directly or have libraries that support it – Proxy servers can be configured to support it but it helps to understand the tradeoffs • Web standards – ETags • Cache busting - updating the cache when a resource is updated
  • 17. Things to avoid • Doing everything in one method (handle inputs, query database, transform results, handle errors, etc.) • Raw SQL – More of a strong guideline but raw SQL can become brittle – Take advantage of the ORM and data models • NOT writing tests – When you have to change a schema/model or refactor your code, how do you know things still work without tests?
  • 18. Exercising your API • Postman - https://www.getpostman.com/ • Allows you to test all of the different verbs • Allows you to create collections of related requests • You can set headers and body data for requests • Allows you to define different environments to parameterize requests
  • 20. www.securitymetrics.com Questions? ● My email: mmandersonii@securitymetrics.com ● Slides: https://www.slideshare.net/MikeAnderson64/creating-a-restful-api-without- losing-too-much-sleep
  • 21. www.securitymetrics.com Thank you! ● My email: mmandersonii@securitymetrics.com ● Slides: https://www.slideshare.net/MikeAnderson64/creating-a-restful-api-without- losing-too-much-sleep