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

kjson-roda

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kjson-roda

  • 0.1.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Kjson

Usage

require 'roda'

class App < Roda
  route do |r|
    r.plugin :kjson

    r.api do
      r.endpoint "user" do
        r.endpoint "new" do
          r.success {"name": "Emmy"}
        end
      end
    end
  end
end

run App.freeze.new

Create a successful response

r.api do
  r.success
end

An alternative way is,

class AlwaysSuccessService
  def call
    throw :success
  end
end

r.api do
  r.endpoint "always_success" do
    service = AlwaysSuccessService.new
    service.()
  end
end

It will generate,

{
  "data": null
  "error": null
}

Fill data in response

r.api do
  r.success data
end

Or,

r.api do
  throw :success, data
end

A complex endpoint

For request {"endpoint":"part.value","data":null},

r.api do
  r.endpoint "part" do
    puts r.endpoint # "value"
  end
end

An arbitrary exception

r.api do
  raise "Something went wrong."
end

Response will look as:

{
  "data": null,
  "error": {
    "type": "SERVICE_ERROR",
    "message": "INTERNAL",
    "cause": {
      "message": "Something went wrong."
    }
  }
}

A service exception

r.api do
  throw :error, "RESOURCE_EXHAUSTED"
end

Response will look as:

{
  "data": null,
  "error": {
    "type": "SERVICE_ERROR",
    "message": "RESOURCE_EXHAUSTED"
  }
}

FAQs

Package last updated on 21 Mar 2017

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