Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

blest

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blest

  • 1.0.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

BLEST Ruby

The Ruby reference implementation of BLEST (Batch-able, Lightweight, Encrypted State Transfer), an improved communication protocol for web APIs which leverages JSON, supports request batching by default, and provides a modern alternative to REST.

To learn more about BLEST, please visit the website: https://blest.jhunt.dev

For a front-end implementation in React, please visit https://github.com/jhuntdev/blest-react

Features

  • Built on JSON - Reduce parsing time and overhead
  • Request Batching - Save bandwidth and reduce load times
  • Compact Payloads - Save even more bandwidth
  • Single Endpoint - Reduce complexity and facilitate introspection
  • Fully Encrypted - Improve data privacy

Installation

Install BLEST Ruby from Rubygems.

gem install blest

Usage

Router

The following example uses Sinatra.

require 'sinatra'
require 'json'
require 'blest'

# Instantiate the Router
router = Router.new(timeout: 1000)

# Create some middleware (optional)
router.before do |body, context|
  if context.dig('headers', 'auth') == 'myToken'?
    context['user'] = {
      # user info for example
    }
    nil
  else
    raise RuntimeError, "Unauthorized"
  end
end

# Create a route controller
router.route('greet') do |body, context|
  {
    greeting: "Hi, #{body['name']}!"
  }
end

# Handle BLEST requests
post '/' do
  json_body = JSON.parse(request.body.read)
  headers = request.env.select { |k, _| k.start_with?('HTTP_') }
  result, error = router.handle.call(json_body, { 'headers' => headers })
  content_type :json
  if error
    raise Sinatra::Error.new(error.status || 500, error)
  else
    result
  end
end

HttpClient

require 'blest'

# Create a client
client = HttpClient.new('http://localhost:8080', max_batch_size = 25, buffer_delay = 10, http_headers = {
  'Authorization': 'Bearer token'
})

# Send a request
begin
  result = client.request('greet', { 'name': 'Steve' }, { 'auth': 'myToken' }).value
  # Do something with the result
rescue => error
  # Do something in case of error
end

License

This project is licensed under the MIT License.

FAQs

Package last updated on 31 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc