diff --git a/content/ai-system/api-fundamentals/index.md b/content/ai-system/api-fundamentals/index.md index f298eee..bf1096b 100644 --- a/content/ai-system/api-fundamentals/index.md +++ b/content/ai-system/api-fundamentals/index.md @@ -39,12 +39,6 @@ We should also briefly address the [difference between a URL and a domain](https > - [Network ports explained](https://www.youtube.com/watch?v=h5vq9hFROEA) > - [Understanding URLs](https://www.youtube.com/watch?v=5Jr-_Za5yQM) -> **Extended Reading:** -> If you are interested in concepts in computer networking that we left behind, take a look at these materials: -> - https://www.geeksforgeeks.org/computer-networks/open-systems-interconnection-model-osi/ -> - https://www.geeksforgeeks.org/computer-networks/basics-computer-networking/ -> - https://learn.microsoft.com/en-us/training/modules/network-fundamentals/ - ### HTTP Protocol & Methods To send a letter in the real world, you first have to choose from available postal services, which you will probably choose based on price, delivery time, previous experiences, etc. For APIs, you usually won't spend time choosing postal services (transfer protocols) since they are largely standardized, and that one standard protocol used in most APIs is called **[HTTP (HyperText Transfer Protocol)](https://www.geeksforgeeks.org/html/what-is-http/)**. @@ -70,12 +64,6 @@ User-Agent: SomeAIApp/1.0 ``` Here, `Authorization` is for identifying the user and protecting the API and is usually where we specify our API keys. `Content-Type` and `Accept` specify the format of data we're sending and the expected response, respectively. `User-Agent` identifies the type of application or client we are using to interact with the API. -> **Extended Reading:** -> Just the `Authorization` header alone could cost us a few modules if we were to explore all types of authorization. For now, just think of it as a place to enter our API keys. We will dive deeper into this topic when we implement our own API server in Module 3: [Wrap AI Models with APIs](@/ai-system/wrap-ai-with-api/index.md), and if you are curious, here are some materials that you can look into: -> - https://apidog.com/blog/http-authorization-header/ -> - https://swagger.io/docs/specification/v3_0/authentication/bearer-authentication/ -> - https://auth0.com/intro-to-iam/what-is-oauth-2 - For the `GET` method, only the request line and headers, or sometimes just the request line, is enough. For the `POST` method, since we are sending data, we need the **body** which is the content of the letter itself. As you noticed, in the headers we've stated that the format of the body will be `application/json`, which means our body will look like this: ```json { @@ -179,10 +167,6 @@ POST /api?method=chat # Generic endpoint > **Videos:** > - [What is a REST API?](https://www.youtube.com/watch?v=lsMQRaeKNDk) -> **Extended Reading:** -> If you want to use a more SQL query-like API interaction method, where you explicitly define the type and scope of data you want and receive exactly that, consider GraphQL: -> - https://graphql.org/learn/ - ## Interact with APIs in Practice Now we've established the basic concepts related to APIs, we will look at how to interact with APIs in practice. diff --git a/content/ai-system/wrap-ai-with-api/index.md b/content/ai-system/wrap-ai-with-api/index.md index aa5302d..c3c305b 100644 --- a/content/ai-system/wrap-ai-with-api/index.md +++ b/content/ai-system/wrap-ai-with-api/index.md @@ -212,11 +212,6 @@ Now if the request body contains invalid data types, FastAPI will reject the req > - [FastAPI tutorial](https://www.youtube.com/watch?v=iWS9ogMPOI0) > - [Pydantic tutorial](https://www.youtube.com/watch?v=XIdQ6gO3Anc) -> **Extended Reading:** -> There are many more benefits and functionalities of integrating `pydantic` to define and abstract data models in FastAPI, including reusability and automatic documentation generation. Generally speaking, when implementing API servers, data model abstraction is a preferred practice. Take a look at more things you can do with both libraries combined: -> - https://data-ai.theodo.com/en/technical-blog/fastapi-pydantic-powerful-duo -> - https://www.geeksforgeeks.org/python/fastapi-pydantic/ - ### API Versioning As we covered in [Advanced APIs in the Era of AI](@/ai-system/advanced-apis/index.md#api-versioning), API versioning allows you to introduce changes without breaking existing integrations. This is particularly important for AI APIs where models and features are constantly evolving. FastAPI makes implementing URL path versioning straightforward using `APIRouter` with prefixes. @@ -472,11 +467,6 @@ Now only the request with authentication header `Authorization:Bearer your-secre The limitation of the above implementation is that your API key is hardcoded. In practice you will want to have a dynamic list of API keys, one for each user, which also enables you to identify each request and keep track of the usage of users. -> **Extended Reading:** -> Comprehensive overview of authentication and authorization in FastAPI: -> - https://www.geeksforgeeks.org/python/authentication-and-authorization-with-fastapi/ -> - https://betterstack.com/community/guides/scaling-python/authentication-fastapi/ - ### Database Integration Continue on the above topic, one common practice for recording the list of API keys and their respective users and other information is through databases. In previous [AI og data](https://www.moodle.aau.dk/course/view.php?id=50254) course we already hands-on concepts of databases and interact with databases through SQL queries. You can directly use database connectors and integrate SQL queries into your API server, but similar to the `pydantic` library for managing data models, we also have `sqlalchemy` for managing data models for databases. @@ -676,11 +666,6 @@ And in our `/classify` route, add one line of code at the start of the function: Now if a user sends more than 5 requests within one minute, their requests will be rejected with a `429 Too Many Requests`. In practice you might also want to record users' rate limit threshold in the `User` data model instead of hardcoding it. -> **Extended Reading:** -> A few libraries for easier implementation of rate limiting: -> - https://github.com/laurentS/slowapi -> - https://github.com/long2ice/fastapi-limiter - ## Exercise Build an image classification API server that demonstrates knowledge covered in this module, reversing your role from API consumer to producer.