Optic is easy to use with FastAPI, no special library or large code changes required.
api start Command#
Let's say we have a simple FastAPI server that we usually develop with on localhost:3005.
Our optic.yml file would include our start command (such as
uvicorn main:app --port $PORT). The start command in this case also sets the port to which the application binds. Optic injects a
$PORT environment variable for our application to listen on when
api start is run. FastAPI accepts the
--port option, which sets the port on which the application will bind. There should be no need to make any code changes.
api check start#
The setup tool will guide you through running checks to assure Optic is running successfully with your API project. You should see everything pass at this point. If you don't, it's most likely that you're not starting the API on the
$PORT Optic provides. The Optic check will also report any other common issues it detects and give you steps and suggestions to resolve them.
At this point you should be ready to run
api start and document your API with Optic! Optic will observe your API traffic locally, and report on the routes and traffic shape it sees in the Optic dashboard. The next step is to start building your baseline specification