Coder Social home page Coder Social logo

Comments (2)

waiting-for-dev avatar waiting-for-dev commented on July 17, 2024 1

Oh! Thanks for the clarification @jodosha , that makes sense :)

from router.

jodosha avatar jodosha commented on July 17, 2024

@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
  1. Use the implicit builder of config.ru. Alternatively you can wrap both use Rack::MethodOverride and run router into an explicit Rack::Builder

  2. The incoming requests will be handled by Rack::MethodOverride first, to apply its logic.

  3. 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.