Implement API via Django and Djano rest framework that:
- allows user to register and login via API
- allows authenticated user to search address or transaction of ETH BTC or BCH (you can use blockchain.info API to check transactions and addresses)
- All searches should be logged and user should be able to see his past searches and mark and address as 'mine'
- All views, serializers and logic must have tests (we prefer numpy)
Bonus:
a. index past searches with elastic search and have an suggestion endpoint for the search box
b. wrap your application in docker with gunicorn and nginx server in reverse proxy
c. make some minimal frontend for the search / search history / my addresses functionality (login is not required, we will set the access token manually in the localStorage using chrome dev tools) There is no need to write tests for the frontend! d. describe your API with apiary
mkdir myproject
cd myproject
python3 -m venv venv
Then installing the Django and Django Rest Framework library:
pip install django
pip install djangorestframework
In addition, in this project requests library is used.
pip install reqests
To build the Database, it requires to do the migrations
:
python manage.py makemigrations <paymentapi>
python manage.py migrate
Then create the superuser:
python manage.py createsuperuser
I am using Bitcoin Developer Center API for retrieving the blocks info.
https://api.bitaps.com/{currency}/v1/blockchain/ currency: btc, eth, bch
Transactions: /transaction/{hash}
Address state: /address/state/{address}
Address transactions: /address/transactions/{address}
For more information, visit the below link: https://developer.bitaps.com/blockchain
After installing prerequisites, now you are ready to run the application. To run it in developer mode, use the below command:
python manage.py runserver
To regsiter new user: /register/
To Login: /api-auth/login/
To logout: /api-auth/logout/
To search for new cryptocurrencies blocks based on available address: /address/
To search for new cryptocurrencies blocks based on available hash: /transaction/
To query your address-based searches: /address/history/
To query your hash-based searched: /transaction/history/
To run the test case, use the below command:
python manage.py test
To test the coverage test, first we should install below package:
pip install coverage
After that we can run the below command to create the coverage report:
coverage run --source='.' manage.py test paymentapi
After creating the report, there are two ways to show the report, one on the command line and the other is in HTML format.
coverage report -m
coverage html -d <dir-name>
A simple document for this API was build by Apiary: https://blockchain14.docs.apiary.io/
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.