Code Monkey home page Code Monkey logo

hackerrank_nodejs_simplecrud2's Introduction

Blog Posts API Medium

Data:

Example of a post data JSON object:

 {
    "isPublished": true,
    "title": "Overcoming Bias in Recruiting to Create a Culture of Diversity & Inclusion",
    "author": 1,
    "timestamp": 1531522701000,
    "publishedDate": 1598775265079,
    "id": 1
}

Project Specifications:

The model implementation is provided and read-only.

The task is to implement the REST service that exposes the /posts endpoint, which allows for managing the collection of blog posts in the following way:

  • POST request to /posts:

    • creates a new blog post
    • expects a JSON blog post object without the id and without the publishedDate properties as the body payload. You can assume that the given object is always valid.
    • adds the given post object to the collection of blog posts and assigns a unique integer id to it. The first created post must have id 1, the second one 2, and so on.
    • if the isPublished property for a post payload object is true, sets the publishedDate to current system time in milliseconds before saving.
    • the response code is 201, and the response body is the created post object
  • GET request to /posts:

    • return a collection of all posts
    • the response code is 200, and the response body is an array of all post objects ordered by their ids in increasing order
    • optionally accepts query parameters author and isPublished, for example /posts?author=1&isPublished=true. All these parameters are optional. In case they are present, only objects matching the parameters must be returned.
    • only the values true or false are valid for the isPublished query param. If any other value is passed in the request, it should be discarded and isPublished property must not be queried upon as the data type is Boolean.
  • GET request to /posts/:

    • returns a post with the given id
    • if the matching post exists, the response code is 200 and the response body is the matching post object
    • if there is no post with the given id in the collection, the response code is 404 with the response body having the text ID not found.
  • DELETE,PUT, PATCH request to /posts/:

    • the response code is 405 because the API does not allow deleting or modifying posts for any id value

You should complete the given project so that it passes all the test cases when running the provided unit tests. The project by default supports the use of the SQLite3 database.

Environment

  • Node Version: ^12.18.2
  • Default Port: 8000

Read Only Files

  • test/*

Commands

  • run:
bash bin/env_setup && . $HOME/.nvm/nvm.sh && npm start
  • install:
bash bin/env_setup && . $HOME/.nvm/nvm.sh && npm install
  • test:
bash bin/env_setup && . $HOME/.nvm/nvm.sh && npm test

hackerrank_nodejs_simplecrud2's People

Contributors

prasunmax avatar

Watchers

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