Beginner
to Guru
What is an API?
What is an API?
• API - Application Programming Interface
• API is a rather broad term - covering a wide range of meanings
• Application - A computer application
• Web Site, Mobile Application, any computer program
• Programming - Instructions to complete a task
• Interface - A point where two systems meet and interact
• An API is a method for two computer applications to speak to each other
Type of APIs
• APIs come in many flavors
• Clicking on a link in an email message is executing an API
• Tells your device to open the web browser and go to this website
• This action is performed via an API
• Some APIs are very technology specific - considered CLOSED
• For example on a mobile device where one application opens another
• Others adopt broadly accepted standards - considered OPEN
The Programable Web
• APIs allow the internet to function as we know it
• For example - searching Google for a term
• Your web browser does a HTTP POST of the search term to Google’s servers
• Googles servers understand the HTTP POST and respond back with an HTML document
• Your web browser understands HTML - this is the language to describe the results web page
APIs In This Course
• This course will focus on the type of APIs used in web development
• These API follow Open standards and are widely used
• These types of APIs are often referred to as Web Services
• Two primary types of Web Services are
• SOAP - older legacy systems
• RESTful - modern adoption, widely used
• Course will focus on RESTFul Web Services
RESTful Web Services
• Because of their simplicity and versatility, RESTful web services have become the de facto
standard for web services.
• REST - Representational State Transfer
• Representation - Typically JSON or XML
• State Transfer - Typically via HTTP
• Established by Roy Fielding from his 2000 doctoral dissertation
RESTful Terminology
• Verbs - HTTP Methods: GET, PUT, POST, DELETE
• Messages - the payload of the action (JSON/XML)
• URI - Uniform Resource Identifier
• A unique string identifying a resource
• URL - Uniform Resource Locator
• A URI with network information - http://www.example.com
RESTful Terminology
• Idempotence -
• Wikipedia “Idempotence is the property of certain operations in mathematics and computer
science that they can be applied multiple times without changing the result beyond the initial
application.”
• In other words, you can exercise the operation multiple times, without changing the result.
• Example: Refreshing a web page (HTTP GET operation)
RESTful Terminology
• Stateless - Service does not maintain any client state
• HATEOAS - Hypermedia As The Engine of Application State
• Wikipedia - “a REST client should then be able to use server-provided links dynamically to
discover all the available actions and resources it needs. As access proceeds, the server
responds with text that includes hyperlinks to other actions that are currently available.”
HTTP - GET
• Use: to read data from resource
• Read only
• Idempotent
• Safe operation - does not change state of resource
HTTP - PUT
• Use: to insert (if not found) or update (if found)
• Idempotent - Multiple PUTs will not change result.
• Like saving a file multiple times
• Not Safe operation - does change state of resource
HTTP - POST
• Use: to create new object (insert)
• Non-Idempotent - Multiple POSTs is expected to create multiple objects
• Not Safe operation - does change state of resource
• Only Non-Idempotent, Non-Safe HTTP verb
HTTP - DELETE
• Use: to delete an object (resource)
• Idempotent - Multiple DELETEs will have same effect / behaviour.
• Not Safe operation - does change state of resource