Comments (2)
Oh! Thanks for the clarification @jodosha , that makes sense :)
from router.
@waiting-for-dev You cannot use Hanami::Router
like that. In the code above you're mounting Rack::MethodOverride
inside the router.
The logic that turns _method
into a meaningful HTTP method for the router is inside the router, so it will never get hit.
What you want to do is this instead:
# frozen_string_literal: true
require "hanami/router"
require "rack/method_override"
use Rack::MethodOverride
router = Hanami::Router.new do
get "/with_get", to: ->(*) { [200, {}, ["with GET"]] }
delete "/with_delete", to: ->(*) { [200, {}, ["with DELETE"]] }
end
run router
-
Use the implicit builder of
config.ru
. Alternatively you can wrap bothuse Rack::MethodOverride
andrun router
into an explicitRack::Builder
-
The incoming requests will be handled by
Rack::MethodOverride
first, to apply its logic. -
Finally the manipulated Rack env can hit the router.
One note regarding cURL examples: by looking at Rack::MethodOverride
code, only POST requests are considered for method overriding.
The correct manual testing would be:
$ curl -i -X POST -d '_method=DELETE' http://localhost:9999/with_delete
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Server: WEBrick/1.4.2 (Ruby/2.6.3/2019-04-16)
Date: Mon, 29 Jul 2019 14:54:06 GMT
Connection: Keep-Alive
with DELETE
from router.
Related Issues (20)
- BodyParser's fallback "_" key in env["router.params"] unnecessary for typical x-www-form-urlencoded bodies? HOT 2
- http_router dependency generates `warning: URI.unescape is obsolete` HOT 3
- Warning: URI.unescape is obsolete HOT 2
- Nested variables/resources HOT 2
- Fake support for Ruby 3 HOT 2
- POST route recognised as GET HOT 2
- 405 response does not include Allow header
- Surprising prefix behavior HOT 2
- Unclear errors with differently named wildcard segments HOT 5
- URL fragments and routing HOT 2
- Exception when JSON body contains % HOT 7
- Failing edge cases for optional variables
- Path segments in base_url can get clobbered by UrlHelpers
- Per-slice middleware not being applied correctly? HOT 3
- Capture names affects finding nested routes HOT 2
- Catch-all has higher priority than mount HOT 2
- Routes with multiple variables not working in common nested route scenario HOT 2
- Inconsistent trailing slash behaviour HOT 1
- Middleware usage does not work as expected
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from router.