rentry-co

Rentry-Co

A Full CRUD super-lite rentry.co wrapper with typescript support and no-dependencies library.

Features

Installation

npm i rentry-co

Usage

Import the library

// src/lib/rentry.js

// CommonJS
const RentryCo = require("rentry-co");
// ESM
import RentryCo from "rentry-co";

/*=============================*/

// Use It
const rentry = new RentryCo();
export default rentry;

Create a new entry

async function test() {
  // id is optional, skip for random id
  var res = await rentry.create({
    id: "<ID>",
    content: "Hello World",
  });
  console.log(res);
}

Output :

save token & id for feature use !

{ "status": "200", "token": "abxx12xx", "id": "abc123" }

Read entry

async function test() {
  var res = await rentry.read({ id: "<ID>" });
  console.log(res);
}

Output :

{ "status": "200", "content": "## Hi\nHello World" }

Update an existing entry

async function test() {
  var res = await rentry.update({
    id: "<ID>",
    token: "<TOKEN>",
    content: "## Hi\nHello World",
  });
  console.log(res);
}

Output :

{ "status": "200", "content": "OK" }

Delete entry

async function test() {
  var res = await rentry.delete({
    id: "<ID>",
    token: "<TOKEN>",
  });
  console.log(res);
}

Output :

{ "status": "200", "content": "OK" }

Express routes

Use built-in expres routes from RentryCoExpress to create api.

note: body-parser, cors are required, install with npm i body-parser cors

import express from "express";
import bodyParser from "body-parser";
import cors from "cors";

import RentryCoExpress from "./index";

const app = express();
app.use(bodyParser.text());
app.use(cors());

app.use("/api/rentry", RentryCoExpress);

app.listen(3000, () => {
  console.log("server started at: http://localhost:3000");
});

License

MIT License