adamcooke / moonrope Goto Github PK
View Code? Open in Web Editor NEWA library to help with building an RPC-like JSON API
License: MIT License
A library to help with building an RPC-like JSON API
License: MIT License
Hi there,
I've started using staytus thanks for that a great app.
I'm a little confused by the non-REST implementation of the api however.
The standards are defined quite well and are very common these days: https://gist.github.com/joyrexus/40d5ac6017be2c71e1ba
Normally one would do a GET /api/v1/monkey/1 to get object :id 1
Forcing users to do a POST to a /info endpoint is very unintuitive?
or am i misreading something?
I spent some time figuring out how the api was hooked into rails as that too is non standard?
Im interested in contributing to this app as its very useful and I'm grateful for it. And I would start at once with re-implementing the api probably using https://github.com/ruby-grape/grape
I'd appreciate your feedback.
Thanks
We were having a go with atech/postal's API natively in PHP instead of using an existing client library and encountered a minor issue during our testing.
In PHP, converting an empty array (or an array without named keys) to JSON results in square bracket wrapped output []
as opposed to curly braces {}
which makes sense.
However sending []
instead of {}
to an API powered by Moonrope causes an error here:
moonrope/lib/moonrope/param_set.rb
Line 32 in f67428a
[web.1:3047] [2019-07-18T14:42:12.036] INFO -- : Started POST "/api/v1/send/message" for redacted at 2019-07-18 14:42:12 +0100
[web.1:3047] [2019-07-18T14:42:12.041] INFO -- : NoMethodError
[web.1:3047] [2019-07-18T14:42:12.041] INFO -- : undefined method `has_key?' for []:Array
[web.1:3047] [2019-07-18T14:42:12.041] INFO -- : /opt/postal/vendor/bundle/ruby/2.5.0/gems/moonrope-2.0.1/lib/moonrope/param_set.rb:32:in `_value_for'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/moonrope-2.0.1/lib/moonrope/action.rb:242:in `block in validate_parameters'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/moonrope-2.0.1/lib/moonrope/action.rb:229:in `each'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/moonrope-2.0.1/lib/moonrope/action.rb:229:in `validate_parameters'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/moonrope-2.0.1/lib/moonrope/action.rb:160:in `block in execute'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/moonrope-2.0.1/lib/moonrope/action.rb:112:in `convert_errors_to_action_result'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/moonrope-2.0.1/lib/moonrope/action.rb:156:in `execute'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/moonrope-2.0.1/lib/moonrope/request.rb:113:in `execute'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/moonrope-2.0.1/lib/moonrope/rack_middleware.rb:88:in `call'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/moonrope-2.0.1/lib/moonrope/doc_server.rb:118:in `call'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/rack-2.0.6/lib/rack/tempfile_reaper.rb:15:in `call'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/rack-2.0.6/lib/rack/etag.rb:25:in `call'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/rack-2.0.6/lib/rack/conditional_get.rb:38:in `call'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/rack-2.0.6/lib/rack/head.rb:12:in `call'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/actionpack-5.2.2.1/lib/action_dispatch/http/content_security_policy.rb:18:in `call'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/rack-2.0.6/lib/rack/session/abstract/id.rb:232:in `context'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/rack-2.0.6/lib/rack/session/abstract/id.rb:226:in `call'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/actionpack-5.2.2.1/lib/action_dispatch/middleware/cookies.rb:670:in `call'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/actionpack-5.2.2.1/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2.1/lib/active_support/callbacks.rb:98:in `run_callbacks'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/actionpack-5.2.2.1/lib/action_dispatch/middleware/callbacks.rb:26:in `call'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/actionpack-5.2.2.1/lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/actionpack-5.2.2.1/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2.1/lib/rails/rack/logger.rb:38:in `call_app'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2.1/lib/rails/rack/logger.rb:28:in `call'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/actionpack-5.2.2.1/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/actionpack-5.2.2.1/lib/action_dispatch/middleware/request_id.rb:27:in `call'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/rack-2.0.6/lib/rack/method_override.rb:22:in `call'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/rack-2.0.6/lib/rack/runtime.rb:22:in `call'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2.1/lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/actionpack-5.2.2.1/lib/action_dispatch/middleware/executor.rb:14:in `call'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/actionpack-5.2.2.1/lib/action_dispatch/middleware/static.rb:127:in `call'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/rack-2.0.6/lib/rack/sendfile.rb:111:in `call'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/secure_headers-6.0.0/lib/secure_headers/middleware.rb:13:in `call'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/sentry-raven-2.7.4/lib/raven/integrations/rack.rb:51:in `call'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2.1/lib/rails/engine.rb:524:in `call'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/puma-3.12.0/lib/puma/commonlogger.rb:38:in `call'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/puma-3.12.0/lib/puma/configuration.rb:225:in `call'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/puma-3.12.0/lib/puma/server.rb:658:in `handle_request'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/puma-3.12.0/lib/puma/server.rb:472:in `process_client'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/puma-3.12.0/lib/puma/server.rb:332:in `block in run'
/opt/postal/vendor/bundle/ruby/2.5.0/gems/puma-3.12.0/lib/puma/thread_pool.rb:133:in `block in spawn_thread'
Obviously while such occurrences should be few and far between, presumably it would be possible for Moonrope to catch any error whilst handling the input at some point and return 400 Bad Request
instead of 500 Internal Server Error
?
Link for screenshot is not valid anymore (returns 404):
https://github.com/adamcooke/moonrope/blob/master/README.md#L16
For example
param :id, "The ID", :type => [Integer, Array]
How do I accept JSON input as a parameter without an associated name for the input? Is there a means to grab the raw body of the request and parse from there?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.