Sling Academy
Home/FastAPI/Page 4

FastAPI

FastAPI AttributeError: ‘dict’ object has no attribute ‘encode’

Updated: Aug 09, 2023
This concise, straight-to-the-point article will walk you through a couple of different solutions to fix a common error you might encounter when working with FastAPI. The Problem Here is the error message: AttributeError: 'dict'......
2 Ways to Implement Pagination in FastAPI

2 Ways to Implement Pagination in FastAPI

Updated: May 18, 2023
Introduction Pagination is a process of dividing a large amount of data into smaller chunks. It is important because it can improve the performance, usability, and security of your backend project. This article will walk you through......
FastAPI: Render HTML Templates with Dynamic Content

FastAPI: Render HTML Templates with Dynamic Content

Updated: May 16, 2023
Overview FastAPI is often used to develop backend APIs. However, you can also use this web framework to render HTML templates and create websites with the help of the HTMLResponse class (can be imported from fastapi.responses) and......

FastAPI: How to Return a TXT or JSON File

Updated: May 16, 2023
This concise, practical article shows you how to return a TXT or a JSON file in FastAPI. I assume you already have some understanding of the web framework, so I won’t waste your time by explaining what FastAPI is, how well it works,......

3 Ways to Get User’s IP Address in FastAPI

Updated: Apr 24, 2023
When building backend applications with FastAPI, you may need to get the IP addresses of your users for several purposes, such as: Geolocation: With an IP address, you can determine the user’s location, which can be useful for......
FastAPI: How to extract request headers (2 approaches)

FastAPI: How to extract request headers (2 approaches)

Updated: Apr 18, 2023
This concise, practical article will walk you through a couple of different ways to extract headers from an incoming request in FastAPI. What are HTTP headers? Headers are part of HTTP messages that pass additional information......

How to Return a CSV File in FastAPI

Updated: Mar 19, 2023
CSV stands for Comma Separated Values. It is a plain text file that stores data by delimiting data entries with commas. CSV files are popular in Python apps because they are easy to read and write using the built-in csv module. They are......
FastAPI: How to Upload and Validate Files

FastAPI: How to Upload and Validate Files

Updated: Mar 19, 2023
This concise, straightforward article shows you how to upload and validate files in a FastAPI application. Uploading Files The Steps To receive and handle files as well as form data from incoming requests in FastAPI, we need......
FastAPI: Allowing Requests from Other Origins (CORS)

FastAPI: Allowing Requests from Other Origins (CORS)

Updated: Mar 19, 2023
Introduction By default, a FastAPI application does not allow requests from different origins than its own domain. Allowing requests from different origins in FastAPI is a common scenario when you have a frontend application......

Getting the Request Body in FastAPI

Updated: Mar 19, 2023
In POST requests, values are sent in the body of the request. When the client side wants to upload files or images, they are most likely sent with a media type of multipart/form-data or application/x-www-form-urlencoded. In FastAPI,......

Serving Static Files in FastAPI: Tutorial & Example

Updated: Jan 19, 2023
This tutorial shows you how to serve static files (images, CSS files, Javascript files, HTML files, or something like that) in FastAPI. Before getting started, you can see a live demo at the URL shown......
How to Create an XML Sitemap in FastAPI

How to Create an XML Sitemap in FastAPI

Updated: Dec 21, 2022
This article walks you through a step-by-step guide to generating an XML Sitemap with FastAPI. Without any further ado, let’s get started. What is an XML Sitemap? An XML Sitemap is an XML file that contains a list of URLs on......