Git Product home page Git Product logo

users-list-api's Introduction

Users Listing API

Develop an API endpoint to get a list of users.

Requirements

  • Pagination support
  • Filtration support
  • Cache-Control (client and server-side)

Commands

npm run dev # run the API in development mode
npm run test # test using Jest
npm run coverage # test and open the coverage report in the browser
npm run lint # lint using ESLint
npm run docs # generate API docs

Playing locally

Run the server in development mode.

npm install
npm run dev
Express server listening on http://0.0.0.0:9000, in development mode

Playing with Docker Compose

To run the application locally, you can use the Docker Compose tool.

docker-compose -f docker-compose.local.yaml up
Express server listening on http://0.0.0.0:9000, in compose mode

And to run the tests locally using Docker Compose.

docker-compose -f docker-compose.test.yaml up

API Docs

You can find the API documentation in the DOCS.md file. This file is autogenerated by the apiDoc inline APIs documentation tool.

Cache-Control

Cache-Control is set to public, max-age=300 in the response headers. This means that the response will be cached for 300 seconds.

You can find Cache-Control directives configured in the express service file.

app.use(cacheController({ public: true, maxAge: 300 }))

Server-Side Caching

Server-Side caching is enabled by default and configured in the middlewares file. The response will be cached for 300 seconds.

const cache = (duration) => {
  return async (req, res, next) => {
    const key = '__express__' + req.originalUrl || req.url

    const cached = await ioredis.get(key)
    if (cached) {
      const json = JSON.parse(cached)
      return success(res)(json)
    } else {
      res.sendResponse = res.send
      res.send = (body) => {
        ioredis.set(key, body, 'EX', duration * 1000)
        res.sendResponse(body)
      }
      return next()
    }
  }
}

Heroku Deployment

This application is deployed to Heroku via this link.

users-list-api's People

Contributors

mohllal avatar

Watchers

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