Skip to content

Liquid Prep Node Backend is a Typescript and Express framework based service to cater the requests from the Liquid Prep App.

Notifications You must be signed in to change notification settings

Liquid-Prep/LiquidPrep-Node-Backend

Repository files navigation

Liquid Prep Node Backend - Typescript + Express

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.

Contents

Build and run the backend

Pre-requisites

  1. Node and NPM

  2. IBM Cloudant Database

  3. The Weather Company API Key

    • Contact The Weather Company to register and subscribe the 5 day weather forecast API and obtain an API key
  4. 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 and CLOUDANT_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

Build and run the backend on your local machine

  1. Build the service
    • Start a terminal/CMD in ~/LiquidPrep-Node-Backend/ folder
    • Execute the command npm install to install the node modules
  2. 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.

Build and run the backend as docker container

Pre-requisites

  1. Install Docker on your local machine.

Run the Backend as docker container

  1. Build docker image

    • Start a terminal/CMD in ~/LiquidPrep-Node-Backend/ folder.
    • Execute the command docker build --tag liquidprep/backend:dev .
  2. 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.

The backend APIs

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:

  1. 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) or m (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
    
  2. 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.068

    http://localhost:5000/api/v1/liquidPrep/location/data?geoCode?geoCode=42.359,-71.068
    
  3. 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
    
  4. 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
    

Contributing

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.

License

Unless otherwise noted, this project is licensed under the Apache 2 License - see the LICENSE file for details.

About

Liquid Prep Node Backend is a Typescript and Express framework based service to cater the requests from the Liquid Prep App.

Resources

Stars

Watchers

Forks

Packages

No packages published