Can you explain why OAuth is important?
In the early days of internet, sharing information was straightforward. Just share your username and password and they could access anything they wanted.
But oh course this is not what we want as customers right now, to give websites this much power.
OAuth 2 is like giving someone a special key. It gives access to an application to specific information in another application, say Facebook user info, but not friends info. We control who gets access to our data, without having to share our password. And we can revoke that key at anytime.
An example, is an image store app and the third party application we want to print the pictures with. Print app request access to photos and when we grant it, the printing app can access our photos without knowing about our login credentials.
How does OAuth work in a nutshell?
Tell me about Message Queues
Message queue is a software component that enables the different parts of a system work asynchronously by sending and receiving messages. They act in the middle and enable the sender and receiver act independently.
Message queues are crucial for building scalable, loosely coupled and fault-tolerant systems.
Can you share some tips about building and secure APIs?
1. Use clear naming: It tells a lot to developers about if they are dealing with a group of resource or one single resource, etc…
2. Make apis idempotent: APIs will likely to be called more than once, so we need to make sure they are idempotent, meaning they won’t create duplicate records or do weird stuff at the backend. For this, we can get a client generated unique ID on every client request so the second time, the api can say, object already exists, etc.
**3. Add versioning: ** To not impact our current API consumers, and to support backward compatibility, we need to make proper versioning for new features.
Say: /api/v1/carts/123 can be /api/v2/carts/123
4. Add pagination: To enhance the performance of our APIs and improve the user experience, we need to limit the amount of data sent to the client. For this, we can use pagination. There are 2 common ways in pagination: cursor-based and page number + offset.
5. Use clear query strings for sorting and filtering data:
Examples for this:
GET /users?sort_by=registered
GET /products?filter=color:blue
-This helps developer to instantly grasp the active filters or sorts already applied. It is much easier to add new sorting or filtering criteria over time without breaking the existence ones. And third, we can actually cache existing filtered results and re-use them.
6. Think about security early on: Use HTTP headers for sensitive data like API keys, instead of URLs. Request headers can also be exposed, so use TLS encryption at every step. And use robust Access Control by verifying keys and tokens every step of the request processing.
7. Keep cross-resource references simple: For example, one item in a cart should be simply referenced like: /api/v1/cart/123/item/456 but not like /api/v1/items?card_id=123&item_id=456 This avoids messy query parameters and helps developers consuming your API.
8. Plan for rate-limiting: This avoids the overload of our systems in the case of an abuse. It protects infrastructure. Ways to do it, 20 reqs per sec from one IP, or free-tier clients can do 1000 requests in a day etc.
What is REST API?
REST is the most common communication standard between computers over Internet. It is simple and good enough for most companies, that’s why it is widely used. API stands for Application Programming Interface. It is a way for two computers to talk to each other. The common API standard used by most mobile and web applications to talk to the servers is called REST. It stands for REpresentational State Transfer.
REST is not a specification. It is a new set of rules that has been the common standard for building web API since the early 2000s. An API that follows the REST standard is called a RESTful API.
What are the basics of REST API?
What is GraphQL?
GraphQL is a query language for API developed by Meta. It provides a schema of the data in the API and gives clients the power to ask for exactly what they need.
How does GraphQL work?
GraphQL sits between the clients and the backend services. It could aggregate multiple resource requests into a single query. It also supports mutations, and subscriptions.
- Mutations are GraphQL’s way of applying data modifications to resources.
- Subscriptions are GraphQL’s way for clients to receive notifications on data modifications.
Can you compare REST and GraphQL?
Both send HTTP requests and receive HTTP responses.
Both make a request via a URL.
Both can return a JSON response in the same shape.
Differences:
- With GraphQL, we specify the exact resources we want, and also which fields we want.
GET /graphql?query={ book(id: “123”) { title, authors { name } } }
In REST example, the API implementer decided this for us that authors are included as related resources. In GraphQL, the client decides what to include. This is a benefit of GraphQL.
Can you tell me the most popular API Architecture styles?