Code Monkey home page Code Monkey logo

marvel-test-api's Introduction

IMPORTANT Notice: This is a test project.


MARVEL API

This is a simple mavel characters api.

Requirements

Install Node.js on your machine.

installation

  1. Install dependencies

    npm install
  2. copy /.env.example to /.env and update the .env file with your Marvel's api keys (MARVEL_PUBLIC_KEY & MARVEL_PRIVATE_KEY). you can get the Marvel's api keys from Marvel's Developers Site. The default port is set to 8080 but you can change it in the .env file

    PORT=8080
    
    MARVEL_PUBLIC_KEY=your-public-key
    MARVEL_PRIVATE_KEY=your-private-key
    
  3. Build the project

    npm run build
  4. Run the app

    npm run start

    Access the api docs on http://localhost:8080/docs

Test

To run the tests

npm run test

 

Code Explanation

/characters caching strategy

In this project node-cache library was used to do an in-momory caching. Refer to character.service.ts file to see the code. Below are the steps taken to cache the results obtained from Marvel's API:

  1. Get the last modified character & total number of characters in Marvels API using /characters endpoint with (orderBy: '-modified' and limit:1).
  2. Compare the last_modified timestamp obtained in step 1 with the cached last_modified value.
    • If both values are equal, then serve the data from the cache
    • If not equal, then get the latest list from Marvel’s API then store the results in the cache and update the cached last_modified.

Getting all characters data from Marvel’s API

After we get the total number of records (poinit 1 above), we create an array of javascript promises. Each promise will have a limit of 100 records. So if the total number of characters on Marvel’s API is 1450, 15 promises will be created and run concurrently to get the data. After getting all the data we will filter the ids only cache then in memory.

marvel-test-api's People

Contributors

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