GithubHelp home page GithubHelp logo

rodrigoieh / kylin-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kylin-network/kylin-api

0.0 1.0 0.0 90 KB

License: MIT License

Dockerfile 1.11% Makefile 1.91% Python 96.66% Shell 0.32%

kylin-api's Introduction

Kylin API

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.git

Running with Docker

To run the server with Docker, you'll need to install Docker if you havent already. Then, you can run:

docker-compose up -d

This will start two Docker containers:

  • kylin-api: Gunicorn server that wraps the Flask app defined in api/app.py
  • postgres: PostgreSQL database

You should now be able to send:

curl localhost:8080/health

And 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 down

Running Locally

To run the server locally, you'll need to install a few requirements. To do this, run:

pip install -r requirements/common.txt

If you are running a local PostgreSQL instance, create an 'SQLALCHEMY_DATABASE_URI' environment variable:

export SQLALCHEMY_DATABASE_URI="YOUR CONNECTION STRING"

If you plan on writing to the database, you'll need to create a parachain_data table as defined in schemas.sql.

Finally, to boot up the server, run:

bash bin/run.sh

You should now be able to interact with your server as described above.

Example Calls

Get current price data:

curl "http://localhost:8080/prices?currency_pairs=btc_usd"

Get historical price data:

curl "http://localhost:8080/prices/hist?currency_pair=ethusd&before=1642438800&after=1642352400&period=180"

Write to database:

curl -d '{"data": "This is json serializable data", "feed": "demo_feed", "block": "1", "hash": "demo_hash"}' -H "Content-Type: application/json" http://localhost:8080/submit

Query database:

# select all data
curl http://localhost:8080/query/all

# select by hash
curl "http://localhost:8080/query?hash=demo_hash"

# select by feed
curl "http://localhost:8080/query?feed=demo_feed"

Testing the API

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.txt

Then from the root directory, run:

pytest

This runs tests/test_api.py which contains test functions.

Accessing the Swagger

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 the default namespace you will see the list of the endpoints available. You can test them using the try_out button.

kylin-api's People

Contributors

loganbonsignore avatar samelamin avatar mshankarrao avatar aalavanthan18 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.