Coder Social home page Coder Social logo

thresholds's Introduction

Thresholds

A platform & protocol independent library for making remote procedure calls behave like normal code, based on decorators.

What?

A threshold is some class or object that has been exposed via an arbitrary protocol.

A client can 'consume' a threshold, and automatically generate a client using the consumer API. No need to generate code, or manually implement a client. It just works.

Show Me

Imagine a very simple http service that allows consumers to post and read notes.

Normally, you would either manually write or generate explicit code to do so.

However, to speed things up a bit, we can use our fancy decorators to take care of the boring stuff.

import { expose } from '@thresholds/core';

class NoteService {
  constructor() {
    this.notes = [];
  }

  @expose('http', { route: '/notes', method: 'post' })
  addNote(note) {
    this.notes.push;
  }

  @expose('http', { route: '/notes', method: 'get' })
  getNotes() {
    return this.notes;
  }
}

We can then start the service up with a simple call:

import { useExposer, exposeInstance from '@thresholds/core';
import { HttpExposer } from '@thresholds/http-exposer';

useExposer('http', new HttpExposer(9080));

await exposeInstance(new NoteService(), {
  route: '/schema',
  method: 'get'
});

And that's it, we are now exposing our chatserver over http. This is already pretty handy, but things get even easier in the client:

import { useConsumer, consume } from '@thresholds/core';
import { HttpConsumer } from '@thresholds/http-consumer';

thresholds.useConsumer('http', new HttpConsumer());

const chatApi = await thresholds.consume<ChatApi>('http', {
  url: 'http://localhost:9090/manifest'
});

The consumption protocol is pretty convenient, as it will return an object that has ready baked implementations for the server side implementation, with the exact same names!

await chatApi.addNote('hello world');
await chatApi.getNotes(); // [ 'hello world']

Why Tho?

  • Development speed - you can standup new services and start writing against them at a rapid pace.
  • Code Reduction - removing boilerplate servers and clients reduces the amount of code you need to write, test and remember.
  • Best practices - transports implementations will (eventually) represent the best patterns for their specific use case
  • Portability - transports can be changed without needing to alter source code.
  • Customization - You can use a pre baked transport, or create your own.
  • Cross platform (eventually)

Disclaimer

This is all still very much in the 'experimental' stage. None of the apis are even close to being concrete.

Roadmap

Rough looking trello board here: https://trello.com/b/aXc3NZJz/thresholds

thresholds's People

Contributors

chordmemory avatar dependabot[bot] 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.