no-more-rest
TypeScript icon, indicating that this package has built-in type declarations

0.0.8 • Public • Published

NO MORE REST

No more rest calls! Call directly your backend APIs from EVERYWHERE! 🌍🚀

Simplify and boost your development process, with this small package you are allowed to integrate continuously your backend APIs and your client code directly.

With a smart generator that create in real time (with a -watch mode) a small proxy, you're able to call transparently your remote functions with all the support you need (intellisense, types, return types and more).

Table of Contents

  1. Installation
  2. Usage
  3. Configuration
  4. Dependencies
  5. Examples

Installation

Install the package on the server project with npm i no-more-rest

Usage

Wrap your APIs and expose via express in this way

//server/myApi.js

export function doLogin(username, password) {
  return username == "admin" && password == "admin";
}

export function getLoggedUsers() {
  return ["Elon Musk", "admin"];
}
// server/server.js

import express from "express";
import { expose } from "no-more-rest";

import * as myApi from "./myApi";

const app = express();
expose(app, myApi);

app.listen(8000);
  • Add this npm script to your package to generate the proxy script for the client from the exposed module
"scripts": {
   "sync-api": "no-more-rest --input myApi.js --output-dir ../your-client-path/ --watch"
}
  • Import in the client your generated proxy and use it as if it were on your backend.
// client/index.js
import { doLogin, getLoggedUsers } from "./generatedProxy";

doLogin("admin", "admin")
  .then((result) => {
    if (result) {
      alert("Login success");

      getLoggedUsers().then((users) => {
        alert("The logged users are: " + users.join(", "));
      });
    } else {
      alert("Login failed");
    }
  })
  .catch(() => {
    alert("Network error");
  });

Configuration

The no-more-rest cli support these parameters

  • --input - the file that exposes the functions

  • --output-dir - The destination folder

  • --typescript-output - Typescript output format

  • --filename - Filename to generate

  • --watch - Watch and generate the proxy file

Dependencies

Actually body-parser is a dependency on the server to be able to parse json body.

Examples

Here the first basic working example 💪🏽

  1. basic-js

Readme

Keywords

Package Sidebar

Install

npm i no-more-rest

Weekly Downloads

0

Version

0.0.8

License

MIT

Unpacked Size

33.6 kB

Total Files

25

Last publish

Collaborators

  • epavanello