This API is set up for use with Python >= 3.7 and Docker. You can set-up your local environment manually or compose up with docker to launch a containerised version of the API.
git clone https://github.com/Kylin-Network/kylin-api.gitTo run the server with Docker, you'll need to install Docker if you havent already. Then, you can run:
docker-compose up -dThis will start three Docker containers:
- kylin-api: Gunicorn server that wraps the Flask app defined in
api/app.py - postgres: PostgreSQL database
- redis: Redis database and memory cache
You should now be able to send:
curl localhost:8080/healthAnd receive the response OK and status code 200. You can see other example calls, here.
Your server and database are running in a detached state as indicated by -d. When you are ready to bring down your server, run:
docker-compose downTo run the server locally, you'll need to install a few requirements. To do this, run:
pip install -r requirements/common.txtIf you are running a local PostgreSQL instance, create an 'SQLALCHEMY_DATABASE_URI' environment variable:
export SQLALCHEMY_DATABASE_URI=YOUR_CONNECTION_STRINGIf you plan on writing to the database, you'll need to create a parachain_data and user table as defined in schemas.sql.
To enable rate limits, declare your 'RATELIMIT_STORAGE_URL' environment variable:
export RATELIMIT_STORAGE_URL=YOUR_CONNECTION_STRINGFinally, to boot up the server, run:
bash bin/run.shYou should now be able to interact with your server as described above.
Get API key:
curl -d '{"wallet": "YOUR WALLET ADDRESS"}' -H "Content-Type: application/json" "http://localhost:8080/auth/register"Get price feed:
curl -H "x-api-key: YOUR_API_KEY" "http://localhost:8080/prices/spot?currency_pairs=btc_usd"Write to database:
curl -d '{"para_id": "para id", "account_id": "account id", "requested_block_number": "1", "processed_block_number": "1", "requested_timestamp": "1633728007913.35", "processed_timestamp": "1633728007913.35", "payload": "This is json serializable data", "feed_name": "demo_feed", "url": "url"}' -H "x-api-key: YOUR_API_KEY" -H "Content-Type: application/json" "http://localhost:8080/parachain/submit"Query database:
curl -H "x-api-key: YOUR_API_KEY" "http://localhost:8080/parachain/query?feed=demo_feed"Testing the API is set up using pytest. To execute tests you can install the project's development dependencies with:
pip install -r requirements/develop.txtThen from the root directory, run:
pytestThis runs tests/test_api.py which contains test functions.
With the application running, use the browser to search the following:
http://localhost:8080/You can see the API's specification and try it directly from the swagger UI.
Inside each namespace you will see the list of the endpoints available. You can test them using the try_out button.