npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

power-of-api

v0.8.1

Published

API in 2 min, Run APIs

Downloads

11

Readme

Getting Started with power-of-api

power-of-api is an easy-to-use, lightweight JavaScript library that provides a simple and efficient way to perform CRUD (Create, Read, Update, Delete) operations on various data storage options, including file storage, MongoDB, and in-memory storage.

Features

Getting Started

To start using power-of-api, simply install it via npm:

npm install --save power-of-api

How to run

In Memory

Use below command to import the package and running with simple configuration

// File: index.js
import app from 'power-of-api';

// In Memory configuration
const port = 1337; // port can be configurable
app.port(port)
    .start(() => {
        console.log(`Server start at ::${port}`)
    }, (err) => {
        console.log(`Exception: `, err)
    });

In File storage

Create db-data folder in root path and provide the path to app as mentioned below to utlize the folder to store the data.

// File: index.js
import app from 'power-of-api';

import path from 'path'
import inFileManager from 'power-of-api/plugins/in-file-manager.js';

const port = 1337
app.port(port)
    .use({
        dbManager: await inFileManager.getDbManager({
            folderPath: path.resolve('./db-data')
        })
    })
    .start(() => {
        console.log(`Server start at ::${port}`)
    }, (err) => {
        console.log(`Exception: `, err)
    });

MongoDB

You need to install mongodb package in your project, to utilize mongodb data store.

npm install [email protected]

Use below code, to configure the app to utilize mongodb data store.

// File: index.js
import app from 'power-of-api';

import { MongoClient, ObjectId } from 'mongodb'; 
import mongodbManager from 'power-of-api/plugins/mongodb-manager.js';

const port = 1337
app.port(port)
    .use({
        dbManager: await mongodbManager.getDbManager({ MongoClient, ObjectId }, {
            url: 'mongodb://localhost:27017',
            dbName: 'powerofapi'
        })
    })
    .start(() => {
        console.log(`Server start at ::${port}`)
    }, (err) => {
        console.log(`Exception: `, err)
    });

To run the API, simply execute node index.js in your terminal.

Once installed, you can use the following curl commands for CRUD operations:

Create

Below endpoint can be used to insert multiple records into the system.

curl --location 'http://localhost:1337?tablename=movies' \
--header 'Content-Type: application/json' \
--data '{
    "items": [
        {
            "name": "Jai Hanuman",
            "actors": [
                {
                    "name": "Teja",
                    "characterName": "Hanumanthu",
                    "castType": "Protagonist"
                }
            ],
            "technicians": [
                {
                    "name": "Prashanth Varma",
                    "technicianType": "Director"
                }
            ]
        },
        {
            "name": "Wall.e",
            "technicians": [
                {
                    "name": "Andrew Stanton",
                    "technicianType": "Director"
                }
            ]
        }
    ]
}'

Read

For now, we are able load all the records for the table.

curl --location 'http://localhost:1337?tablename=movies'

Update

With the below endpoint and data format, we can update multiple records with _id as primary key in the table.

curl --location 'http://localhost:1337?tablename=books&method=update' \
--header 'Content-Type: application/json' \
--data '{
    "items": [
        {
            "_id": "ffdb2dd18ced25d90118304518fff7e1178",
            "fieldsToUpdate": {
                "authors": [
                    {
                        "name": "Space Ranger"
                    },
                    {
                        "name": "Green star"
                    }
                ]
            }
        }
    ]
}'

Delete

We can delete multiple records with below endpoint, using _id as primary key.

curl --location --request DELETE 'http://localhost:1337?tablename=movies' \
--header 'Content-Type: application/json' \
--data '{
    "items": [
        {
            "_id": "bfbd53acaf873e384814f5dc18fff7d05ed"
        }
    ]
}'

Advanced Configruations

License

MIT

Contributing

We welcome contributions from the open-source community! If you'd like to contribute to power-of-api, please follow best practices and submit a pull request.

Thank you for using power-of-api!