Setting up an API on Render within 5 minutes

One of the best ways to productivize software is to sell an API. My preffered host is Render, and I'm gonna show you how to host an API on render within 5 minutes.

First, you need the code. Here’s a basic, 1 file main.py that you see for reference.

from fastapi import * import uvicorn from fastapi.middleware.cors import CORSMiddleware app = FastAPI() app.add_middleware( CORSMiddleware, allow_origins = ['*'], allow_credentials= True, allow_methods= ['*'], allow_headers = ['*'] ) @app.get('/') def read_root(): return{'Status': 'Active'} @app.get('/test_endpoint') def testEndpoint(): return{'Test Status': 'Successful'} if __name__ == "__main__": uvicorn.run(app, host="0.0.0.0", port=10000)

Super simple, only a root endpoint and a test_endpoint, both GET.

After you’ve set up your original api and and installed all the libraries, run this command in your terminal:

pip freeze > requirements.txt

This command will install a requirements.txt file with everything you will need. Example:

annotated-types==0.6.0 anyio==4.2.0 click==8.1.7 colorama==0.4.6 fastapi==0.109.2 h11==0.14.0 idna==3.6 pydantic==2.6.1 pydantic_core==2.16.2 sniffio==1.3.0 starlette==0.36.3 typing_extensions==4.9.0 uvicorn==0.27.1

This tells Render what it needs to install.

If you’re using FastAPI like me, you’ll want to run this as your build command:

uvicorn main:app --host 0.0.0.0 --port 10000

The last thing you need to do is specify the Python Version you are using in the Environment section.

Once these are set, you’re good to go!