Giter Club home page Giter Club logo

api-testing's Introduction

Express Server with CI/ CD

This repository demostrates making a simple REST API with Express and Node. It includes authorization, authentication functionality with Firebase as well as the ability to cache results into Redis after reading from a local MongoDB instance.

Instead of using a database and hosting it online, we use local data for users.

Interacting with the POST, PUT and DELETE commands will change the contents of the file.

Setup

To setup after cloning, run npm install to install all necessary packages.

Once done, run the node server using npm start.

It is automatically configured to run on PORT 8080.

Alternatively, the API is hosted on Google Cloud, and can be accessed using this link.

Testing

For testing our API, we use the dependencies mocha, chai and chai-http.

To run the unit tests, run npm test.

API details

For Authorization and Authentication:

Our API supports two types of users, viewers, logged in viewers and admins.

Normal viewers are not authenticated, that is to say, they can only view the bare minimum.

To see what a normal viewer can access, refer to userRouter.

Logged in users can get access to extra data as they are authenticated users. To authenticate a user, you would have to login with an email and a password.

However, logged in users may not be authorized to all data, and some data are protected only for those with an 'admin' role.

To see what a logged in user and admin can access, refer to adminRouter. We provide authentication and authroization checks in middleware.


For Redis caching:

We are reading data from a local MongoDB database instance. It has 500 records inside.

To prevent our server from repeatedly querying this endpoint, we cache the result into our Redis cache with a current TTL of 30s.

When querying data, take note of the key fromCache in our JSON response, as having it to true means that we are reading from cache while having it to false means that we are reading from the database itself.

api-testing's People

Contributors

ryancheungjf avatar

Watchers

 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.