Giter Site home page Giter Site logo

js-fwdays-2018's Introduction

FWday workshop source-code

The task

Your task is to build a REST API that exposes methods to interact with a cache that you will build. You will have to use Node.js and Express.js to build the API and MongoDB to store the cache data in. The cache does not have another data source in the background that is cached. All data returned by the cache is random dummy data. You do not need to build a frontend. The API shall be used with tools like curl or Postman.

Following features have to be implemented for the cache:

  • Add an endpoint that returns the cached data for a given key. If the key is not found in the cache:
    1. Log an output “Cache miss”
    2. Create a random string
    3. Update the cache with this random string
    4. Return the random string
  • If the key is found in the cache:
    1. Logan output “Cache hit”
    2. Get the data for this key
    3. Return the data
  • Add an endpoint that returns all stored keys in the cache
  • Add an endpoint that creates/updates the data for a given key
  • Add an endpoint that removes a given key from the cache
  • Add an endpoint that removes all keys from the cache

Following additional features have to be also included:

  • The number of entries allowed in the cache is limited. If the maximum amount of cached items is reached, some old entry needs to be overwritten (Please explain the approach of what is overwritten in the comments of the source code)
  • Every cached item has a Time To Live (TTL). If the TTL is exceeded, the cached data will not be used. A new random value will then be generated (just like cache miss). The TTL will be reset on every read/cache hit

Development Tooling

Configuration

Check .env.example file, create .env or set environments variables.

Running

  • Start MongoDB via docker-compose up or add URI link to the environment
  • npm start

Testing Approach

  • standart with standard is used for checking code style and JS best practice..
  • dredd is used for swagger and rest api testing.

Development Approach

Boundaries

In this part our application store any 3-rd party connection, state and etc. They have start/stop for bootstraping.

Controls

In this part we store our business logic.

Settings

We use dotenv-safe package for checking environment variables. If you miss part of the settings, then application will not start.

Logger

We use bunyan

Bootstraping and Gracefull shatdown

app.js is implemented for Bootstraping and Gracefull shatdown. Can be reused for tests.

Additional features

MongoDB used for this features.

  • TTL
  • capped
  • @TODO: move from db.js to migrations. How we will implement them?

js-fwdays-2018's People

Contributors

galkin avatar

Watchers

 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.