This is an example proxy for CarAPI built in NodeJS/Express. The application is a simple proxy and is suitable for local development. You can use this as a basis for what you'd deploy to production or write your own. A proxy is ideal for client-side developers who need to interact with CarAPIs CORs restricted API.
Why use a proxy for your client-side application? To prevent impersonation through JWT theft.
- Docker and Docker Compose
Put your API Token and API Secret in an environment config file at app/.env
and if neccessary your CORS_ORIGIN. A sample file is provied at app/.env.example
:
API_TOKEN=""
API_SECRET=""
CORS_ORIGIN="http://localhost"
docker-compose up
The server will simply forward any requests made to http://localhost:3000/proxy
to https://carapi.app
. For example, to make a request to the /api/years
endpoint you'd make a request to http://localhost:3000/proxy/api/years
. Anything the API documentation supports is supported by the proxy including query parameters such as http://localhost:3000/proxy/api/years?make=tesla
.
There are a number of ways to deploy your application: AWS, Heroku, Railway and more. While CarAPI doesn't support your infrastructure, we found Railway to be an easy option for someone less familiar with cloud or VPS providers to easily deploy a NodeJS application.
- Create an account with Railway.
- Connect your Railway to your Github account through the Railway setup wizard.
- Add your secrets to railway as Railway Variables.
- Deploy your application.
- Setup Public Networking in your applications Settings.
Railway will automate deployments as you push to your main branch.