Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6925005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:44:02+00:00 2026-05-27T10:44:02+00:00

We can write get ‘/foo’ do … end and post ‘/foo’ do … end

  • 0

We can write

get '/foo' do
  ...
end

and

post '/foo' do
  ...
end

which is fine. But can I combine multiple HTTP verbs in one route?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T10:44:03+00:00Added an answer on May 27, 2026 at 10:44 am

    This is possible via the multi-route extension that is part of sinatra-contrib:

    require 'sinatra'
    require "sinatra/multi_route"
    route :get, :post, '/foo' do
      # "GET" or "POST"
      p request.env["REQUEST_METHOD"]
    end
    
    # Or for module-style applications
    class MyApp < Sinatra::Base
      register Sinatra::MultiRoute
      route :get, :post, '/foo' do
        # ...
      end
    end
    

    However, note that you can do this simply yourself without the extension via:

    foo = lambda do
      # Your route here
    end
    get  '/foo', &foo
    post '/foo', &foo
    

    Or more elegantly as a meta-method:

    def self.get_or_post(url,&block)
      get(url,&block)
      post(url,&block)
    end
    
    get_or_post '/foo' do
      # ...
    end
    

    You might also be interested in this discussion on the feature.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i write some utility class but how to get name ? Can that send
I want to write Html format, but I can not even get a simple
How can I get an application to write debug text to the Event Log
How can I get Mathematica to export/save/write a text file with proper Fortan77 formatting,
I am trying to write DOM viewer on JavaScript. How I can get all
I can write such beatiful straightforward code: public int Delta { get; private set;
I know you can write support for custom PSDrives. But those are always a
I'm trying to implement OnListItemClick but can't seem to get it working. There are
How come, in Java, I can write List<?> list = new LinkedList<Double>(); but not
I am trying to write an awk script that can get a block that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.