APIs
(And Restaurants)
![](https://media2.giphy.com/media/3ov9jNziFTMfzSumAw/giphy.gif)
![](https://media2.giphy.com/media/hoKmJa133aQlyW3NhD/giphy.gif)
&
What is an API?
- Application Programming Interface
- A program (software) that is interacted with by other programs (as opposed to human users)
- It can be a web API, where requests are made to a server from a remote client (which is what we are building), but it can also be something like a programming library (a set of prebuilt functions that can be imported into a program)
![](https://media4.giphy.com/media/DfSXiR60W9MVq/giphy.gif)
![](https://media4.giphy.com/media/NsBknNwmmWE8WU1q2U/giphy.gif)
Where our API Fits In
A user performs an action in an app client that makes a request to the app server
The app server makes a request to the Network API
The Network API fulfills the request and sends the data to the app server, which then sends the data back to the client
Relevant Concepts
- Specification
- Requests
- Architecture
- Servers
- Infrastructure
- Databases
- Events
- Background jobs
- Tech debt
![](https://media3.giphy.com/media/ZaRz2080kt4Yg/giphy.gif)
Specification
- Describes how users can interact with the API
- Comprised of requests and their corresponding responses
- Tech example: (GET /users/123 responds with {name: Anakin})
- Analogical example: a restaurant menu
Requests
- A request is how information is accessed from an API
- A response is the fulfillment of a request
- Analogical examples:
- Request – a restaurant customer ordering a meal
- Response – the meal being served
![](https://media2.giphy.com/media/l0G16L3dTIVabxA3e/giphy.gif)
Anatomy of a Request
- A request is made from a client (the program making the request) to a server (the program accepting the request)
- It is comprised of the following components:
- An action/verb, e.g., GET, PUT, DELETE
- An endpoint, e.g., /users/123
- (Sometimes) a payload, e.g., name: Anakin
- It results in a response from the server and, sometimes, other actions, e.g., data being stored in a database
![](https://media3.giphy.com/media/WqFJMEfcwT7u0xZ9gF/giphy.gif)
Architecture
- The design or structure of the API (similar to real-life archetecture)
- Analogical example: the layout of a restaurant, (including the dining area, kitchen, language spoken, design of tables and chairs, placement of the settings, etc.)
![](https://media3.giphy.com/media/l41lFJFBhMDBAS9Ww/giphy.gif)
Servers
- Servers are programs that accept and fulfill requests from clients
- Sometimes computers are referred to as servers but, technically, the term 'server' is referring to the program(s) running on them
- Analogical example: the chefs/cooks in the kitchen preparing ingredients, cooking food, etc.
Infrastructure
- The actual machines that code, databases, etc. are running on
- Analogical example: the ovens, stoves, mixers, counters, etc. in a kitchen
![](https://media3.giphy.com/media/pQKRcEA6GA9S8/giphy.gif)
Databases
- Application-wide data storage and retrieval
- Many different types for many different applications
- Analogical example: The refrigerator and freezer
![](https://media4.giphy.com/media/xT9C25UNTwfZuk85WP/giphy.gif)
Search vs Transactions
- Search is when a client would like a relevant list of results that are (hopefully) related to a given input
- A transaction is when a client is asking for (or providing) something using an exact identifier
- Analogical examples:
- Search: going to the produce section of the grocery store to find vegetables for a salad
- Transaction: scanning a products barcode to find its price, the isle it is stored on, etc.
![](https://media2.giphy.com/media/l0MYHq0IFikDrVQOc/giphy.gif)
Events
- An event refers to a notification after a specific action takes place
- An event is usually followed by some work (another action) being performed
- Analogical examples:
- Event – a customer finishes eating
- Following work – the check is brought to the customer
![](https://media4.giphy.com/media/3oEduXeT0j1Bl5uWHK/giphy.gif)
Background Jobs
- Work performed behind the scenes
- Technical example: an email being created and sent when a user forgets their password
- Analogical example: buspeople cleaning up tables, washing dishes, setting tables, etc.
![](https://media1.giphy.com/media/kxKdMAZO0N99S/giphy.gif)
Technical Debt
- Technical debt is accrued as a byproduct of creating software over a period of time
- It is often quite difficult to understand technical debt until after a product, or enchancement to an existing product is complete (or at least nearly complete)
- Analogical example: the mess created in a kitchen during service, wear and tear on cutlery, broken dinnerware, etc.
![](https://media3.giphy.com/media/gXF3P4m5CMPTy/giphy.gif)
![](https://media4.giphy.com/media/l2JI1JzL6YS8z5KUM/giphy.gif)
APIs (and Restaurants)
By Benji
APIs (and Restaurants)
- 52