Giter VIP home page Giter VIP logo

simple-cache-api's Introduction

Simple Cache API

Simple cache implementation using Express and MongoDB

This code was written in Node v14.17.0

Steps:

Make sure you have Node and MongoDB installed on your system.

Add .env file. Add MongoDB URL to MONGODB_DATABASE_URI in the .env file

After the above steps, run:

npm install

npm start

Got MongoParseError? Make sure the MONGODB_DATABASE_URI is present in the .env file in the src folder

Defaults

Name Value Description
PORT 6060 Port API runs on.
TTL_SECONDS 120 Max TTL of each item in the cache.
MAX_ENTRIES 10 Total number of allowed entries in the cache

You can overwrite these values by adding them in the env file along side with MONGODB_DATABASE_URI

API Endpoints

Below endpoints have been implemented.


Add Item to cache


POST [http://localhost:6060/insert]

Parameters

Name Required Type Description
key required string Unique key for value
value required string Value you want to save

Response

{
    "error": null,
    "key": "k",
    "value": 1
}

Get Item from cache


GET [http://localhost:6060/item]

Parameters

Name Required Type Description
key required string Unique key for value

Response

{
    "error": null,
    "key": "hhhhhhh",
    "value": "7fcdebc5-0b0a-4f13-8a70-154f74f7c2ca"
}

Get All Items from cache


GET [http://localhost:6060/items]

Parameters

Name Required Type Description

Response

{
    "error": null,
    "values": [
        {
            "key": "hhhhhhh",
            "value": "e3a8a02a-f7b9-45ef-8545-8bbebea9028c",
            "ttl": "2022-03-18T18:25:23.845Z"
        },
        {
            "key": "k",
            "value": 1,
            "ttl": "2022-03-18T18:24:03.638Z"
        }
    ]
}

Delete Item from cache


DELETE [http://localhost:6060/item]

Parameters

Name Required Type Description
key required string Unique key for value

Response

No response in case of success

Delete All Items from cache


DELETE [http://localhost:6060/items]

Parameters

Name Required Type Description

Response

No response in case of success

simple-cache-api's People

Contributors

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