Coder Social home page Coder Social logo

be-proto's Introduction

Bè Proto

WARNING: Very alpha and very WIP.

Library and code generator for Protobuf HTTP binding (google/api/http.proto), or some docs.

Hello World Project set-up

Add a proto file to your NPM package or one that you depend upon.

File structure:

- proto
  - hello-service.proto
- package.json

proto/hello-service.proto

syntax = "proto3";

package hello;

import "google/api/http.proto";

service HelloService {
    rpc Greet (Message) returns (Message) {
        option (google.api.http) = {
          get: "/api/greetings"
        };
    }
}

message Message {
  string message = 1;
}

Code generation

Install: npm add --dev be-proto-sdk

Add to package.json

{
  "scripts": {
    "build": "be-codegen http-client --output ./be-client hello.HelloService"
  }
}

Run: npm run build

Use the generated code

Install: npm add --dev be-proto-runtime

const {greet} = require('./be-client/hello/HelloService.Greet');

const {message} = await greet({
  message: 'Hello!'
});

console.log(message); // prints "Hello!"

Using as a server

const {Greet, greet} = require('./be-client/hello/HelloService.Greet';

const beServer = require('be-proto-runtime/server');

const server = await beServer.builder()
  .withBindings(Greet.bind((message) => message))
  .start({ port: 9901 });


const {message} = await greet({
  message: 'Hello!'
}, {
  baseUrl: 'http://localhost:9901'
});

console.log(message); // prints "Hello!"

Proto-less

Install: npm add --dev be-proto-runtime

  const {http, get, messageBuilder, string} = require('be-proto-runtime/http');
  const beServer = require('be-proto-runtime/server');

  const echoMessage = messageBuilder()
    .field('message', string, 1)
    .build();

  const getEcho = http(get('/echo'), echoMessage, echoMessage, {
    fetch, // optionally provide your own fetch
    baseUrl: 'http://localhost:9901'
  });

  const server = await beServer.builder()
    .withBindings(getEcho.bind((message) => message))
    .start({ port: 9901 });

  const {message} = await getEcho.invoke({
    message: 'Hello!'
  }, {
    baseUrl: 'http://localhost:9901'
  });

be-proto's People

Contributors

mantasindrasius avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

be-proto's Issues

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.