Liquid Prep Node Backend service is a Typescript and Express framework based service to cater the requests from the Liquid Prep App. The service exposes API endpoints for Liquid Prep application to query weather and crop information.
-
Node and NPM
- Install Node to build and run the server
-
IBM Cloudant Database
- The IBM Cloudant Database acts a storage for all the crop data. Please refer the setup instructions to host a database on your IBM Cloud account
-
The Weather Company API Key
- Contact The Weather Company to register and subscribe the
5 day weather forecast API
and obtain an API key
- Contact The Weather Company to register and subscribe the
-
Environment variables
-
Create a
.env
file in the project root folder with the following entries:CLOUDANT_URL= CLOUDANT_APIKEY= CLOUDANT_DB_NAME= TWC_WEATHER_API_KEY=
- The
CLOUDANT_URL
,CLOUDANT_APIKEY
andCLOUDANT_DB_NAME
values are all obtained when you setup the IBM Cloudant Database - The
TWC_WEATHER_API_KEY
is obtained from the Weather Company. Please refer to the third pre-requisite on how to obatin the API key
- The
-
- Build the service
- Start a terminal/CMD in
~/LiquidPrep-Node-Backend/
folder - Execute the command
npm install
to install the node modules
- Start a terminal/CMD in
- Run the backend
- Execute the command
npm start
to run the backend service - Open web browser and enter
http://localhost:5000
in the URL section - You should see the message
Liquid Prep Node Backend Server is up and running.
- Execute the command
- Install Docker on your local machine.
-
Build docker image
- Start a terminal/CMD in
~/LiquidPrep-Node-Backend/
folder. - Execute the command
docker build --tag liquidprep/backend:dev .
- Start a terminal/CMD in
-
Run the backend docker container
- Execute the command
docker run -it -d -p 5000:5000 --name liquidprep-backend liquidprep/backend:dev
- Open the web browser and enter
http://localhost:5000
in the URL section - You should see the message
Liquid Prep Node Backend Server is up and running.
- Execute the command
Once the backend service is running, you can test the APIs if they are working as expected. You can test the APIs by simply calling them in any browser (Chrome, Firefox, Edge) or using CURL command or API clients like Postman.
The backend currently supports four APIs:
-
GET 5 Days Weather Data:
Get weather information for a given geo-coordinates.http://localhost:5000/api/v1/liquidPrep/weather/data?geoCode=<lat,long>&units=<metric/imperical>
Query Params:
- geoCode: Geo-coordinates (latitude, longitude) of a location
- units:
e
(metric) orm
(imperial)
Example:
Get weather information for geo-coordinates latitude 42.359, longitude 71.068 and units in metrics (e)http://localhost:5000/api/v1/liquidPrep/weather/data?geoCode=42.359,-71.068&units=e
-
GET location data:
Get location information for a given geo-coordinates.http://localhost:5000/api/v1/liquidPrep/location/data?geoCode=<lat,long>
Query Params:
- geoCode: Geo-coordinates (latitude, longitude) of a location
Example:
Get location information for geo-coordinates latitude 42.359, longitude 71.068http://localhost:5000/api/v1/liquidPrep/location/data?geoCode?geoCode=42.359,-71.068
-
GET Crop List:
Get list of all the crop names and their IDs supported by Liquid Prep.http://localhost:5000/api/v1/liquidPrep/crop/list
-
GET Crop Data:
Get a crop information supported by Liquid Prep.http://localhost:5000/api/v1/liquidPrep/crop/id=<_id>
Path Params:
- id: It is the unique identity number assigned for the crop and can be obtained from list of supported crops by executing the GET Crop List API
Example:
Get crop information for Corn.http://localhost:5000/api/v1/liquidPrep/crop/id=1
- id: It is the unique identity number assigned for the crop and can be obtained from list of supported crops by executing the GET Crop List API
Please read CONTRIBUTING.md for details on our code of conduct, areas where we'd like to see community contributions, and the process for submitting pull requests to the project.
Unless otherwise noted, this project is licensed under the Apache 2 License - see the LICENSE file for details.