{"id":973,"date":"2023-01-31T17:21:00","date_gmt":"2023-01-31T11:51:00","guid":{"rendered":"https:\/\/geekpython.in\/?p=973"},"modified":"2024-10-12T17:04:08","modified_gmt":"2024-10-12T11:34:08","slug":"build-api-using-fastapi","status":"publish","type":"post","link":"https:\/\/geekpython.in\/build-api-using-fastapi","title":{"rendered":"How To Build APIs Using FastAPI In Python With Examples"},"content":{"rendered":"\n<p>API (<strong>Application Programming Interface<\/strong>) is a medium that helps two applications talk to each other. APIs have some set of functions that allows only the asked data from the server requested by the application as a response.<\/p>\n\n\n\n<p>If we put it in simple words, the API takes the request from the application and sends that data to the server. The server processes that data and sends the response back to the application and then the application interprets the data and presents it to the user.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"heading-what-is-fastapi\"><a href=\"https:\/\/geekpython.in\/build-api-using-fastapi#heading-what-is-fastapi\"><\/a>What is FastAPI?<\/h1>\n\n\n\n<p>FastAPI is a modern, high-performance web framework for building Python REST (<strong>Representational State Transfer<\/strong>) APIs. FastAPI is written in Python and is based on&nbsp;<a target=\"_blank\" href=\"https:\/\/docs.pydantic.dev\/\" rel=\"noreferrer noopener\">Pydantic<\/a>&nbsp;and&nbsp;<strong>type hints<\/strong>&nbsp;(tells the type of variables or functions\/methods) to validate the data.<\/p>\n\n\n\n<p>FastAPI offers excellent performance and support while building APIs and it has several key features that let us carry out operations smoothly:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Fast<\/strong>: Provides high-performance<\/li>\n\n\n\n<li><strong>Code rapidly<\/strong>: Increase the speed to develop features.<\/li>\n\n\n\n<li><strong>Easy<\/strong>: It is designed to be easy to use and learn.<\/li>\n\n\n\n<li><strong>Robust<\/strong>: Get production-ready code. With automatic interactive documentation.<\/li>\n\n\n\n<li><strong>Adaptable<\/strong>: Works well with the open standards for APIs like OpenAPI and JSON Schema.<\/li>\n\n\n\n<li><strong>Type hints<\/strong>: Makes it easy for data validation.<\/li>\n\n\n\n<li><strong>Supports asynchronous<\/strong>: It fully supports asynchronous programming. (<a target=\"_blank\" href=\"https:\/\/fastapi.tiangolo.com\/\" rel=\"noreferrer noopener\">Source<\/a>)<\/li>\n<\/ul>\n\n\n\n<p>FastAPI applications can run on both WSGI (<strong>Web Server Gateway Interface<\/strong>) and ASGI (<strong>Asynchronous Server Gateway Interface<\/strong>) HTTP servers. It primarily uses the&nbsp;<strong>ASGI standard<\/strong>&nbsp;which is a spiritual successor to the WSGI.<\/p>\n\n\n\n<p>Another interesting feature FastAPI provides is that it automatically auto-generates the interactive API documentation using the&nbsp;<strong>Swagger UI<\/strong>&nbsp;and&nbsp;<strong>ReDoc<\/strong>.<\/p>\n\n\n\n<p>In this tutorial, we will learn the concepts of FastAPI and implement them while building a simple web API.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"heading-install-fastapi\"><a href=\"https:\/\/geekpython.in\/build-api-using-fastapi#heading-install-fastapi\"><\/a>Install FastAPI<\/h1>\n\n\n\n<p>Before proceeding further in this tutorial, it&#8217;s a good idea to create an\u00a0<a href=\"https:\/\/geekpython.in\/python-virtual-environments-venv\" target=\"_blank\" rel=\"noreferrer noopener\">isolated environment<\/a>\u00a0where we can install the dependencies required to get started.<\/p>\n\n\n\n<p>We will start by installing the\u00a0<strong>FastAPI<\/strong>\u00a0using the\u00a0<strong><em>pip<\/em><\/strong>. Remember you must be on Python version\u00a0<strong>3.7<\/strong>\u00a0<strong>or above<\/strong>.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:ps decode:true \" >(project_fastapi) PS&gt; pip install \"fastapi[standard]\"<\/pre><\/div>\n\n\n\n<p>With that,\u00a0<code>FastAPI<\/code>\u00a0will be installed in our virtual environment and will be ready to use to create the API.<\/p>\n\n\n\n<p><strong>Note:<\/strong>\u00a0In the above command, &#8220;<code>project_fastapi<\/code>&#8221; is the name of the virtual environment created behind the scenes and we activated it and installed the required dependencies. If you run the command &#8220;<code>pip freeze<\/code>&#8220;, you&#8217;ll see the list of dependencies installed in your virtual environment.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"heading-a-basic-api\"><a href=\"https:\/\/geekpython.in\/build-api-using-fastapi#heading-a-basic-api\"><\/a>A Basic API<\/h1>\n\n\n\n<p>The following code shows the basic API created using FastAPI.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \"># api.py\nfrom fastapi import FastAPI\n\napp = FastAPI()\n\n@app.get(\"\/\")\ndef data():\n    return {\"message\": \"Hello, I am a simple API.\"}<\/pre><\/div>\n\n\n\n<p>In the above code, we imported the class&nbsp;<code>FastAPI<\/code>&nbsp;from the&nbsp;<code>fastapi<\/code>&nbsp;module and then created an instance called&nbsp;<code>app<\/code>&nbsp;of the class&nbsp;<code>FastAPI<\/code>.<\/p>\n\n\n\n<p>Next, we created a&nbsp;<strong>path operation decorator<\/strong>&nbsp;that will tell the FastAPI that the function below is responsible for handling the requests given to the path&nbsp;<code>(\"\/\")<\/code>&nbsp;using the &#8220;<code>get<\/code>&#8221; operation.<\/p>\n\n\n\n<p>Then we defined the&nbsp;<strong>path operation function<\/strong>&nbsp;that will return the response whenever the request comes to the specified URL (<code>\"\/\"<\/code>) using a&nbsp;<code>GET<\/code>&nbsp;operation.<\/p>\n\n\n\n<p><strong>We can make our path operation function asynchronous using the<\/strong>&nbsp;<code>async<\/code>&nbsp;<strong>keyword<\/strong>.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">from fastapi import FastAPI\n\napp = FastAPI()\n\n@app.get(\"\/\")\nasync def data():\n    return {\"message\": \"Hello, I am a simple API.\"}<\/pre><\/div>\n\n\n\n<p>Now we can run our application using\u00a0<code>fastapi dev<\/code>. <\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:ps decode:true \" >(project_fastapi) PS&gt; fastapi dev api.py<\/pre><\/div>\n\n\n\n<p>Here,\u00a0<code>fastapi dev<\/code>\u00a0<code>api.py<\/code> will start the development server with the Python file <code>api.py<\/code> which contains the API code.<\/p>\n\n\n\n<p>We&#8217;ll be prompted with the following message.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:ps decode:true \" > \u256d\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 FastAPI CLI - Development mode \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e\n \u2502                                                     \u2502\n \u2502  Serving at: http:\/\/127.0.0.1:8000                  \u2502\n \u2502                                                     \u2502\n \u2502  API docs: http:\/\/127.0.0.1:8000\/docs               \u2502\n \u2502                                                     \u2502\n \u2502  Running in development mode, for production use:   \u2502\n \u2502                                                     \u2502\n \u2502  fastapi run                                        \u2502\n \u2502                                                     \u2502\n \u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\n\nINFO:     Will watch for changes in these directories: ['D:\\\\SACHIN\\\\VS_projects\\\\api']\nINFO:     Uvicorn running on http:\/\/127.0.0.1:8000 (Press CTRL+C to quit)\nINFO:     Started reloader process [12048] using WatchFiles\nINFO:     Started server process [2480]\nINFO:     Waiting for application startup.\nINFO:     Application startup complete.<\/pre><\/div>\n\n\n\n<p>And if we&#8217;ll go to&nbsp;<code>http:\/\/127.0.0.1:8000<\/code>, we&#8217;ll see the response shown in the image below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"878\" height=\"161\" src=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/1-7.png\" alt=\"API Response\" class=\"wp-image-977\" srcset=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/1-7.png 878w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/1-7-300x55.png 300w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/1-7-768x141.png 768w\" sizes=\"auto, (max-width: 878px) 100vw, 878px\" \/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"heading-learn-by-building-api\"><a href=\"https:\/\/geekpython.in\/build-api-using-fastapi#heading-learn-by-building-api\"><\/a>Learn by building API<\/h1>\n\n\n\n<p>Upto here, you might have understood the basic concepts of FastAPI. Now we&#8217;ll understand even more concepts while building an API that will extract the hyperlinks from the specified URL.<\/p>\n\n\n\n<p>Before start building the API, we must install the following libraries that will be required in the process.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>BeautifulSoup4<\/strong><\/li>\n\n\n\n<li><strong>Requests<\/strong><\/li>\n<\/ul>\n\n\n\n<p>We can install these libraries in our virtual environment by running the following command using pip.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:ps decode:true \">(project_fastapi) PS&gt; pip install beautifulsoup4 requests<\/pre><\/div>\n\n\n\n<p>These libraries will help us extract the content of the particular URL and here&#8217;s the guide to&nbsp;<a target=\"_blank\" href=\"https:\/\/geekpython.in\/web-scraping-in-python-using-beautifulsoup\" rel=\"noreferrer noopener\">scraping the webpage using beautifulsoup<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-linkex-api\"><a href=\"https:\/\/geekpython.in\/build-api-using-fastapi#heading-linkex-api\"><\/a>LinkEx API<\/h2>\n\n\n\n<p>Here is a simple API that extracts all the hyperlinks from the URL.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \"># Imported required libs\nfrom fastapi import FastAPI\nfrom pydantic import BaseModel\nfrom bs4 import BeautifulSoup\nimport requests\nimport re\n\n# FastAPI Instance\napp = FastAPI(\n    title=\"Linkex\",\n    description=\"An API to extract the hyperlinks from the URLs.\"\n)\n\n# Data Model\nclass Data(BaseModel):\n    urls: str\n\n# Simple route\n@app.get(\"\/\", tags=[\"Simple Route\"])\ndef get_data():\n    return {\"message\": \"Hello, I am a Linkex API.\"}\n\n# Link extracting route\n@app.post(\"\/\", tags=[\"Extract Links\"])\ndef extract_result(route: Data):\n    r = requests.get(route.urls)\n    htmlContent = r.content\n\n    soup = BeautifulSoup(htmlContent, 'html.parser')\n    anchors = [link.get(\"href\") for link in soup.find_all(\n        \"a\", attrs={'href': re.compile(\"https:\/\/\")})]\n    return {\"Data\": anchors}<\/pre><\/div>\n\n\n\n<p>First, we imported the required libraries used in the code.<\/p>\n\n\n\n<p>Then we created an instance of the FastAPI and this time we declared two arguments called&nbsp;<code>title<\/code>&nbsp;and&nbsp;<code>description<\/code>&nbsp;which will set the&nbsp;<strong>title<\/strong>&nbsp;and the&nbsp;<strong>description<\/strong>&nbsp;of the API.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"881\" height=\"232\" src=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/2-8.png\" alt=\"Title and description of the API\" class=\"wp-image-978\" srcset=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/2-8.png 881w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/2-8-300x79.png 300w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/2-8-768x202.png 768w\" sizes=\"auto, (max-width: 881px) 100vw, 881px\" \/><\/figure>\n\n\n\n<p>Then we created a simple route or&nbsp;<strong>path operation<\/strong>&nbsp;decorator (<code>@app.get(\"\/\", tags=[\"Simple Route\"]<\/code>). Here&nbsp;<code>@app<\/code>&nbsp;is the decorator instance of the FastAPI and&nbsp;<code>get<\/code>&nbsp;is the operation that will tell the route to perform a&nbsp;<code>GET<\/code>&nbsp;operation when the request comes from the (<code>\"\/\"<\/code>) route. We also declared the&nbsp;<code>tags<\/code>&nbsp;argument (takes a list) to name the API route.<\/p>\n\n\n\n<p>Right below the path operation decorator, we defined a&nbsp;<strong>path operation function<\/strong>&nbsp;that handles the logic when the specific endpoint is hit.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"195\" src=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/3-5-1024x195.png\" alt=\"Route names\" class=\"wp-image-979\" srcset=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/3-5-1024x195.png 1024w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/3-5-300x57.png 300w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/3-5-768x146.png 768w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/3-5.png 1330w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>If we hit the (<code>\"\/\"<\/code>) route, we&#8217;ll see the response shown in the image below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"958\" height=\"172\" src=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/4-5.png\" alt=\"LinkEx API response\" class=\"wp-image-980\" srcset=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/4-5.png 958w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/4-5-300x54.png 300w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/4-5-768x138.png 768w\" sizes=\"auto, (max-width: 958px) 100vw, 958px\" \/><\/figure>\n\n\n\n<p>Another route we defined is the&nbsp;<strong>main route<\/strong>&nbsp;that handles the&nbsp;<code>POST<\/code>&nbsp;request and extracts the hyperlinks from the URL specified in the request body.<\/p>\n\n\n\n<p>As usual, we created a&nbsp;<strong>path operation decorator<\/strong>&nbsp;&#8220;<code>@app.post(\"\/\", tags=[\"Extract Links\"])<\/code>&#8221; and this time the operation is&nbsp;<code>post<\/code>&nbsp;to perform the&nbsp;<code>POST<\/code>&nbsp;request.<\/p>\n\n\n\n<p>Then we created a&nbsp;<strong>path operation function<\/strong>&nbsp;called&nbsp;<code>extract_result<\/code>&nbsp;and passed the argument&nbsp;<code>route<\/code>&nbsp;and the type of argument declared is a&nbsp;<strong>Pydantic model<\/strong>&nbsp;called&nbsp;<code>Data<\/code>.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">from pydantic import BaseModel\n\n# Data Model\nclass Data(BaseModel):\n    urls: str<\/pre><\/div>\n\n\n\n<p>To create the Pydantic model, we imported the&nbsp;<code>BaseModel<\/code>&nbsp;from&nbsp;<code>pydantic<\/code>&nbsp;and then created a schema for our model by defining a&nbsp;<code>Data<\/code>&nbsp;class that extends the&nbsp;<code>BaseModel<\/code>&nbsp;and declared the argument&nbsp;<code>urls<\/code>&nbsp;which is of type&nbsp;<code>string<\/code>.<\/p>\n\n\n\n<p>Then we wrote the logic that extracts the links prefixed with&nbsp;<code>https:\/\/<\/code>&nbsp;and displays them from the URL specified in the&nbsp;<strong>request body<\/strong>&nbsp;of the API.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-testing-linkex-api\"><a href=\"https:\/\/geekpython.in\/build-api-using-fastapi#heading-testing-linkex-api\"><\/a>Testing LinkEx API<\/h2>\n\n\n\n<p>Now our API is ready and the next step is to test it to see if it really works and send us the response that we expect from it.<\/p>\n\n\n\n<p>Run the API code and go to&nbsp;<code>http:\/\/127.0.0.1:8000\/docs<\/code>&nbsp;to see the interactive documentation of our LinkEx API powered by&nbsp;<strong>Swagger UI<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"492\" src=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/5-4-1024x492.png\" alt=\"Request body of the API\" class=\"wp-image-981\" srcset=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/5-4-1024x492.png 1024w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/5-4-300x144.png 300w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/5-4-768x369.png 768w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/5-4.png 1344w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>We specified the URL in the&nbsp;<strong>request body<\/strong>&nbsp;of the API and then we sent the request to the API by clicking on the &#8220;<strong>Execute<\/strong>&#8221; button.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"411\" src=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/6-3-1024x411.png\" alt=\"Response body of the API\" class=\"wp-image-982\" srcset=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/6-3-1024x411.png 1024w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/6-3-300x120.png 300w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/6-3-768x308.png 768w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/6-3.png 1345w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Our API successfully extracted the hyperlinks from the URL and displayed them in the&nbsp;<strong>response body<\/strong>&nbsp;of our API.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-path-parameter-or-variable\"><a href=\"https:\/\/geekpython.in\/build-api-using-fastapi#heading-path-parameter-or-variable\"><\/a><strong>Path parameter or variable<\/strong><\/h2>\n\n\n\n<p>We can declare the&nbsp;<strong>path parameters<\/strong>&nbsp;or&nbsp;<strong>variables<\/strong>&nbsp;by using curly braces like we used to do for formatted strings.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">@app.get(\"\/{param}\")\ndef get_data(param: str):\n    return {\"message\": param}<\/pre><\/div>\n\n\n\n<p>If we execute&nbsp;<code>http:\/\/127.0.0.1:8000\/Hello%20World<\/code>, we&#8217;ll get the response &#8220;<strong>Hello World<\/strong>&#8221; because the value of the parameter is passed inside the function as the argument&nbsp;<code>param<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"heading-data-validation\"><a href=\"https:\/\/geekpython.in\/build-api-using-fastapi#heading-data-validation\"><\/a>Data validation<\/h2>\n\n\n\n<p>If we&#8217;ll change the argument&nbsp;<code>param<\/code>&nbsp;from type&nbsp;<code>str<\/code>&nbsp;to type&nbsp;<code>int<\/code>&nbsp;in the above code, and try to pass the value as a string, we&#8217;ll get an easily readable error.<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:python decode:true \">@app.get(\"\/{param}\")\ndef get_data(param: int):\n    return {\"message\": param}<\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"658\" src=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/7-2-1024x658.png\" alt=\"Type error\" class=\"wp-image-983\" srcset=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/7-2-1024x658.png 1024w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/7-2-300x193.png 300w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/7-2-768x494.png 768w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/7-2.png 1052w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>If we try in the API documentation and try to execute it then we&#8217;ll be warned with a message on data validation.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"342\" src=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/8-3-1024x342.png\" alt=\"Error in the API documentation\" class=\"wp-image-984\" srcset=\"https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/8-3-1024x342.png 1024w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/8-3-300x100.png 300w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/8-3-768x256.png 768w, https:\/\/geekpython.in\/wp-content\/uploads\/2023\/08\/8-3.png 1342w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"heading-conclusion\"><a href=\"https:\/\/geekpython.in\/build-api-using-fastapi#heading-conclusion\"><\/a>Conclusion<\/h1>\n\n\n\n<p>In this tutorial, you were introduced to the most basic concepts of FastAPI that will help you get started with FastAPI and build basic web APIs using FastAPI and Python.<\/p>\n\n\n\n<p>We also coded a basic API that extracts the hyperlinks from the specified URL and was able to understand every block of code.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>\ud83c\udfc6Other articles you might like if you liked this article<\/strong><\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/using-transfer-learning-for-deep-learning-model\" rel=\"noreferrer noopener\">Build a custom deep learning model using the transfer learning technique<\/a>.<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/flask-app-for-image-recognition\" rel=\"noreferrer noopener\">Implement deep learning model into Flask app for image recognition<\/a>.<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/argmax-function-in-numpy-and-tensorflow\" rel=\"noreferrer noopener\">Argmax function in TensorFlow and NumPy<\/a>.<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/python-web-app-under-100-lines-of-code-using-streamlit\" rel=\"noreferrer noopener\">Build a Covid-19 EDA and Visualization app using streamlit in Python<\/a>.<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/deploy-streamlit-webapp-to-heroku\" rel=\"noreferrer noopener\">Deploy your streamlit app on Heroku servers in a few steps<\/a>.<\/p>\n\n\n\n<p>\u2705<a target=\"_blank\" href=\"https:\/\/geekpython.in\/one-liners-in-python\" rel=\"noreferrer noopener\">Powerful one-liners in Python to enhance code quality<\/a>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>That&#8217;s all for now<\/strong><\/p>\n\n\n\n<p><strong>Keep Coding\u270c\u270c<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>API (Application Programming Interface) is a medium that helps two applications talk to each other. APIs have some set of functions that allows only the asked data from the server requested by the application as a response. If we put it in simple words, the API takes the request from the application and sends that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":975,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"0","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"off","ocean_gallery_id":[],"footnotes":""},"categories":[2,57],"tags":[58,12,31],"class_list":["post-973","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","category-fastapi","tag-fastapi","tag-python","tag-python3","entry","has-media"],"_links":{"self":[{"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/posts\/973","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/comments?post=973"}],"version-history":[{"count":5,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/posts\/973\/revisions"}],"predecessor-version":[{"id":1818,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/posts\/973\/revisions\/1818"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/media\/975"}],"wp:attachment":[{"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/media?parent=973"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/categories?post=973"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geekpython.in\/wp-json\/wp\/v2\/tags?post=973"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}