Giter Club home page Giter Club logo

shows's Introduction

Description

From the list of shows in the request payload, return the ones with DRM enabled (drm: true) and at least one episode (episodeCount > 0).

The returned JSON should have a response key with an array of shows. Each element should have the following fields from the request:

image - corresponding to image/showImage from the request payload
slug
title

Links

Pre-requisites

You should have node install in order to run the commands below. Check out Nodejs.

Commands

npm install

After cloning this project from github, use 'install' in order to install the projects dependencies in your machine.

npm start

Reserved this for the project's production environment to use. Nothing special, just start the node app.

npm run dev

I am using 'cross-env' to run 'nodemon' and start the server. Part of the script is to explicitly set process.env to 'develoopment'.

npm test

The project using using MOCHA, Chai and Chai-http to test the end point. Running the command will run Nodemon to execute mocha.

Logging

Morgan is used to log the calls being made with the api. The app checks the process.env to make sure to only run the loggin in development.

Hitting the endpoint

Use your tool api tool of choice i.e. Postman.

Create a POST request with a Body using a schema like the sample below:

{
    "payload": [
        {
            "country": "UK",
            "description": "What's life like when you have enough children to field your own football team?",
            "drm": true,
            "episodeCount": 1,
            "genre": "Reality",
            "image": {
                "showImage": "http://mybeautifulcatchupservice.com/img/shows/16KidsandCounting1280.jpg"
            },
            "language": "English",
            "nextEpisode": null,
            "primaryColour": "#ff7800",
            "seasons": [
                {
                    "slug": "show/16kidsandcounting/season/1"
                }
            ],
            "slug": "show/16kidsandcounting",
            "title": "16 Kids and Counting",
            "tvChannel": "GEM"
        }
    ]
}

Sample Response

{
    "response": [
        {
            "image": "http://mybeautifulcatchupservice.com/img/shows/16KidsandCounting1280.jpg",
            "slug": "show/16kidsandcounting",
            "title": "16 Kids and Counting"
        }
    ]
}

Schema Validation using ajv

Made it simple by making sure that the needed properties ('drm','episodeCount') are the right types.

sample response when the 'episodeCount' was sent a string instead of an integer

[
    {
        "instancePath": "/payload/0/episodeCount",
        "schemaPath": "#/properties/payload/items/properties/episodeCount/type",
        "keyword": "type",
        "params": {
            "type": "integer"
        },
        "message": "must be integer"
    }
]

sample error when 'drm' is not a boolean

[
    {
        "instancePath": "/payload/0/drm",
        "schemaPath": "#/properties/payload/items/properties/drm/type",
        "keyword": "type",
        "params": {
            "type": "boolean"
        },
        "message": "must be boolean"
    }
]

Invalid Payload Error

If a post request was made using faulty json schema, the following error will be the app's response.

{
    "error": "Could not decode request: JSON parsing failed"
}

Built With

  • JavaScript
  • Node
  • NPM
  • Express

shows's People

Contributors

rbyusi avatar

Watchers

James Cloos 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.