Giter Site home page Giter Site logo

api_for_wizeline_go_bootcamp's Introduction

API For Wizeline Go Bootcamp

This is an API developed to qualify for the Wizeline Golang Bootcamp.

It mas developed using Node JS ( v16.14.0 ) and Express ( v4.17.3 )

 

The API has two endpoints. Check the "API Definition" section for full details.

 

 

Dependencies

 

All dependencies are included in the package.json files, and need to

be installed before running the application. (Check the "Running The Application" section)

 

Here is a description of the dependencies used:

  • Dotenv: A zero-dependency module that loads environment variables from a .env file

  • Axios: A promise based HTTP client for the browser and node.js

  • Express: A web application framework for Node JS

 

Development Dependencies

 

These libraries are not required to run the application, but they are required for other purposes such as facilitating the development of the application or running tests.

 

  • Nodemon: Automatically restarts the node application when file changes in the directory are detected.

  • Chai: An assertion library for NodeJS and browser

  • Mocha: A testing framework for JavaScript

 

Running The Application

 

Requirements

 

You will need to install Node JS ( v16.14.0 ) and NPM ( v8.3.1 ). Refer to the official NPM documentation for installation instructions:

https://docs.npmjs.com/downloading-and-installing-node-js-and-npm

 

Installing dependencies

 

Before running the application we need to install all the dependencies. You can do this with the following command (execute it from the root directory of this application):

 

npm install  

 

Starting the application

 

Execute the following command from the application directory. The included .env file sets the application to run in port 3001 , you can change the port by editing this file

 

npm start  

 

Execute tests

 

There is a suite of unit tests under the test directory. You can run them with the following command:

 

npm test  

 

Example output

 

API service is running on port: [3001]


  Test GET route /api
    ✔ It should return a hello world message

  Test GET route /api/activity
    ✔ It should return a valid activity if no parameters are provided (246ms)
    ✔ It should return an activity for 4 participants (190ms)
    ✔ It should return a cooking activity for 3 participants (199ms)
    ✔ It should return a social activity (205ms)
    ✔ It should return error if invalid activity type provided (186ms)
    ✔ It should return error if more than 5 participants requested (182ms)
    ✔ It should return error if less than 1 participant requested (183ms)
    ✔ It should return an activity ignorring unsupported paremeters (186ms)


  9 passing (2s) 

API Definition

 

GET /api

Displays Hello World!

Sample Query: http://localhost:3000/api

Response

{"message":"Hello World!"}

 

GET /api/activity

Get a random activity for one participant

Sample Query: http://localhost:3000/api/activity

Response

{
  "activity": "Shop at support your local farmers market",
  "type": "relaxation",
  "participants": 1,
  "price": 0.2,
  "link": "",
  "key": "8979931",
  "accessibility": 0.1
}

 

GET /api/activity?type=:type

Find a random activity with a given type

Sample Query: http://localhost:3001/api/activity?type=social

Response

{
  "activity": "Write a thank you letter to an influential person in your life",
  "type": "social",
  "participants": 1,
  "price": 0,
  "link": "",
  "key": "4101229",
  "accessibility": 0.1
}

 

GET /api/activity?participants=:participants

Find a random activity with a given number of participants

Sample Query: http://localhost:3001/api/activity?participants=2

Response

{
  "activity": "Go swimming with a friend",
  "type": "social",
  "participants": 2,
  "price": 0.1,
  "link": "",
  "key": "1505028",
  "accessibility": 0.1
}

 

  Note that you can use both supported parameters in the request

 

Request Parameters Description
participants The number of people that this activity could involve [1, n]
type Type of the activity ["education", "recreational", "social", "diy", "charity", "cooking", "relaxation", "music", "busywork"]

 

 

Response Fields Description
accessibility A factor describing how possible an event is to do with zero being the most accessible [0.0, 1.0]
price A factor describing the cost of the event with zero being free[0, 1]
key A unique numeric id [1000000, 9999999]
link A link with information about the activity

api_for_wizeline_go_bootcamp's People

Contributors

ealapisco avatar alapisco avatar

Stargazers

 avatar

Watchers

 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.