/bootcamp_aggregator_api

Bootcamp-aggregator-api is an Express/Node.js web application with a MongoDB database that provides a RESTful API for aggregating and reviewing coding bootcamps.

Primary LanguageJavaScript

Bootcamp-aggregator-api

Contents

Introduction

Bootcamp-aggregator-api is an application to aggregate and review bootcamps. This document describes the technologies its build on, how to configure and run the application, it's database schema, those particularities and it's main functionality by an example API request instructions.

Used technology

The application is build with Node.js, the Express framework, and uses MongoDB as a Database. It also utilizes Mongoose to verify the database operation.

Database Schema

The database schemas resources are:

  • Bootcamps
  • Course
  • Review
  • User

Database Schema Visualization

Getting Started view in draw.io

Resource types and their special properties

Bootcamps

Bootcamps have a slug that is created with the package slugify. This slug can be used to display the Bootcamp's url as a path in a frontend application. It is computed before the creation of the Bootcamp using Middleware.

Reviews

A function in the ReviewModel enforces the constraint that each user can only create one review per Bootcamp by a compound index of the User and Bootcamp collections. This enforcement is done by using the Unique Index Property.

Usage

Rename "config/config.env.env" to "config/config.env" and update the values/settings to your own

Install Dependencies

npm i

Run app

# Run in dev mode
npm run dev

# Run in prod mode
npm start

Example database seeder

To seed the database with users, Bootcamps, Courses, and Reviews with exemplary data from the "_data" folder, run

# Destroy all data
node seeder -d

# Import all data
node seeder -i

Example API Request instructions

The documentation for this application's full interface can be found on documenter.getpostman.com.

Get All Bootcamps

This API-request is a get request that returns all document-instances of the Bootcamp entity in the database. It offers multiple params that can be used to define Bootcamp's exact types that should be returned. The functionality for the results of this API request is implemented in bootcamp_aggregator_api/middleware/advancedResults.js.

{{URL}}/api/v1/bootcamps?select=<Bootcamp-property1>&sort=[Bootcamp-property]&page=<page-number>&limit=<limit-number>&<Bootcamp-number-property>[<operator>]='<Bootcamp-number-propert>'

Descripiton of Parameters

  • select=[Bootcamp-property-n]
    • Select the properties that you want to be shown in the query result.
  • ```sort=[Bootcamp-property]``
    • Select a property to sort for.
  • page=[page-number]
    • Switch between the pages of the API-request-return.
  • limit=[page-numbr]
    • Specify the of number pages e.g. how many Bootcamps the returns per request.
  • [Bootcamp-number-property][[operator]]=[operator-target]

Example usage

For all available Bootcamps,

  • get the name, and if they offer housing,
  • sorted by the name of the city,
  • limited the shown results to two per page,
  • and only show those with a cost of less than or equal to (<=) 10,000$.

{{URL}}/api/v1/bootcamps?select=housing,name&sort=city&limit=2&averageCost[lte]='10000'