Node js api for retrieving information about current Bitcoin rate with user sign up and authentification.
Dependecies: used only native node js libraries http
, https
, fs
, crypto
and one external library dotenv
Current Bitcoin currency rate is being taken from https://www.coinapi.io/
-
POST
user/create
body: { email: "[email protected]", password: "examplepassword" }
Query for creating new user. After creating user unque token is generated for this user. Users are saved in
users_data.json
Possible responses:
201: Created user with E-mail: [email protected]
400: Error, your E-mail or password field is empty
400: Error, incorrect email
409: Error, user with this E-mail adress already exists
-
POST
user/login
body: { email: "[email protected]", password: "examplepassword" }
Query to authenticate and get user token. Possible responses:
200: "68dd5aef0c**********************"
- user token400: Error, your E-mail or password field is empty
400: Error, user with this email does not exist
400: Error, password is invalid
-
GET
btc/Rate
headers: { Authorization: "68dd5aef0c**********************" }
With this query you should provide headers with token to tell server that you are authorized.
Possible responses:
200: {cryptoCurrency: "BTC", rate: *BTC rate in UAH*}
401: Error, user is unauthorized
- if token is invalid or does not exist
index.js
- main file with serverapi
- server apiapi.js
- main api module with endpointscryptoCurrency.js
- module with https response to https://www.coinapi.io/security.js
- module with functions that create token, hash passwords and verify passwords
storage
- storage that emulates database. Data is saved in users_data.json, storage api is written in storage/storage.js