GithubHelp home page GithubHelp logo

promocode-api's Introduction

Promocode API

NodeJs Javascript Mysql

This is promocode API program. That allow the user to create a new promocode or request a promocode depending on his age, date and meteo weather.

Getting Started

Prerequisites

Installing node.js

  • Mac (homebrew):
brew install node
  • Linux (packet manager):
sudo apt-get install nodejs npm
  • Node website:
https://nodejs.org/

Installing

  1. Clone the repository project in the directory of your choice with:
git clone https://github.com/vreymond/Promocode-API
  1. Move to the project directory, and install all npm modules dependencies needed by the program
npm install

Program launch

  • To access the helping manual of the Api containing the entire options list, use the following command:
node src/api.js -h 

You will get:

> Usage: api [options]

Options:
  -V, --version             output the version number
  -p, --portAPI <portAPI>   Set API port listening
  -l, --loglevel <logLevel  Set log level
  -h, --help                output usage information

The -l (or --loglevel) option allows you to modify the verbosity of the console logs. To see debug level just use the following command:

node src/api.js -l debug

API usage

All the routes have been tested using the Insomnia program.

1°) API index

You can access the API by using the URL http://localhost:<portAPI>/ (default port is 3000).

2°) API create promo route (GET)

Creating a promo code route using query string URL

http://localhost:3000/create-promo/WeatherCode/20?age=eq40lt30gt15&end=test&start=test&meteo=clair&temp=gt15

age query must be like eq<value>lt<value>gt<value>
(eq and lt/gt are optional, but lt (or gt) cannot exist without gt (or lt))

end and start date are not implemented

Server response:

{
  "message": "WeatherCode promo created!"
}

3°) API ask promo (POST)

Request a promo code depending on the weather:

http://localhost:3000/ask-promo

with post body:
{
    "promocode_name": "WeatherCode",
    "arguments": {
        "age": 25,"meteo": { 
            "town":"Paris"
            }
    }
}

Server response:

{
  "promocode_name": "WeatherCode",
  "status": "accepted",
  "avantage": {
    "percent": "20"
  }
}

Contributors

Valentin Reymond

Promocode API

vreymond

github.com/vreymond

License

This project is licensed under the MIT License - see the LICENSE file for details

promocode-api's People

Contributors

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