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 7677415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:25:02+00:00 2026-05-31T17:25:02+00:00

I have a simple server in Sinatra, like require ‘sinatra/base’ class Server < Sinatra::Base

  • 0

I have a simple server in Sinatra, like

require 'sinatra/base'

class Server < Sinatra::Base

  get '/' do
    "root"
  end

  get '/api/:apiname' do
    "return api from module #{params.apiname}"
  end

end

I want to be able to include modules for each api, which could use Sinatra DSL. It could be like:

module SomeApi
  get '/api_method'
    "result of api call"
  end
end

Then I want to include SomeApi module to my Server class, to be able to get api call result from url “http://localhost/someapi/api_method&#8221;. Is it possible to change my code to be able to do this, or should I use another framework then Sinatra? Thanks a lot!

  • 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-31T17:25:04+00:00Added an answer on May 31, 2026 at 5:25 pm

    Maybe you will find the map method from Rack useful. With it, you could do something like:

    config.ru:

    require 'sinatra/base'
    require './app'
    
    map('/api1'){ run API1 }
    map('/api2'){ run API2 }
    map('/'){ run Server }
    

    app.rb:

    class Server < Sinatra::Base
      get '/' do
        "root"
      end
    
      get '/foo' do
        "foo from Server"
      end
    end
    
    class API1 < Sinatra::Base
      get '/foo' do
        "foo from API1"
      end
    end
    
    class API2 < Sinatra::Base
      get '/foo' do
        "foo from API2"
      end
    end
    

    start server:

    $ thin start
    >> Using rack adapter
    >> Thin web server (v1.3.1 codename Triple Espresso)
    >> Maximum connections set to 1024
    >> Listening on 0.0.0.0:3000, CTRL+C to stop
    

    test it:

    $ curl localhost:3000
    root%
    $ curl localhost:3000/foo     
    foo from Server%    
    $ curl localhost:3000/api1/foo
    foo from API1%
    $ curl localhost:3000/api2/foo
    foo from API2%    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple server that looks something like this: void *run_thread(void *arg) {
Just trying to get simple http server running and have no clue about ruby
I have a simple ruby server something like : app = Proc.new do |env|
I have a simple SQL Server 2008 database with two tables like this: TableA:
I have a simple Python server, import BaseHTTPServer import SimpleHTTPServer PORT = 8080 class
I have simple python server and client. Server: import SocketServer import threading class MyTCPHandler(SocketServer.BaseRequestHandler):
I have a simple client-server app on android. the android service communicates with the
I have a simple client/server setup. The server is in C and the client
Say I have a simple client/server scenario with one method: // client code $client
I have a very simple TCP server written in C. It runs indefinitely, waiting

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.