JSPM

superagent-protobuf

0.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 138
  • Score
    100M100P100Q87092F
  • License MIT

Adds protobuf.js encoding and decoding support to superagent

Package Exports

  • superagent-protobuf

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (superagent-protobuf) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

superagent-protobuf

Adds protobuf.js encoding and decoding support to superagent

Build Status Test Coverage NPM Version

Supports both superagent and supertest on Node.js.

Installation

Install using npm:

$ npm install superagent-protobuf

Usage

superagent-protobuf adds the proto(...) and sendProto(...) methods onto an existing superagent or supertest object.

Installing

// Using require(...).
const request = require('superagent');
require('superagent-protobuf')(request);

// Using ES6 imports.
import request from 'superagent';
import addProtobuf from 'superagent-protobuf';

addProtobuf(request);

The same methods above work with supertest as well:

const request = require('supertest');
require('superagent-protobuf')(request);

request.proto(...)

Decodes a protobuf message with a specified message type.

Note that this method sets the Accept header to application/x-protobuf.

Example usage:

// Send a request and expect a MessageType protobuf.js message back.
let res = await request.get('.../some-endpoint')
  .proto(MessageType);

// The resulting message is stored in the body property.
console.log(res.body);

request.sendProto(...)

Encodes a protobuf message with the Content-Type application/x-protobuf.

Example usage:

let res = await request.post('.../some-endpoint')
  .sendProto(MessageType.create({
    my_field: 1  
  }));

This can also be combined with request.proto(...) to receive a protobuf message as well:

let outbound = MessageType.create({
  my_field: 1  
});

// Sending a MessageType message and receiving an AnotherMessageType
// message.
let res = await request.post('.../some-endpoint')
  .sendProto(outbound)
  .proto(AnotherMessageType);

let inbound = res.body;

// Printing out the message.
console.log(inbound);

License

Released under the MIT License (see LICENSE).