Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to call one endpoint from another modules? #1250

Closed
micfan opened this issue Jan 20, 2016 · 3 comments
Closed

How to call one endpoint from another modules? #1250

micfan opened this issue Jan 20, 2016 · 3 comments

Comments

@micfan
Copy link

micfan commented Jan 20, 2016

API SDL interface feature is required for method calling cross API class. The discuss was posted Grape Google Group. The result may be:

Class Twitter < Grape::API
  params do
    ...
  end
  interface :my_method do 
    return a+b
  end
end

Now the call can by the below, but env is not easy constructed :-(

# ret is an Array
ret = Twitter::API.endpoints[0].call(env)
@qd3v
Copy link

qd3v commented Dec 3, 2018

+ looking for such feature too, in Rails it's easy as (Warden example):

manager.failure_app = lambda { |env| SessionsController.action(:new).call(env) }

@myxoh
Copy link
Member

myxoh commented Dec 12, 2018

In the codebase of an app I work on we do:
APIRoot.call(env) where APIRoot is the endpoint in which everything is mounted. However, you can do this on every parent endpoint.

in our case

# config/routes.rb
RailsApp::Application.routes.draw do
  mount APIRoot => "/api"
end
# app/api/api_root.rb
class APIRoot < Grape::API
  mount OtherEndpoint
  ...
end

@micfan
Copy link
Author

micfan commented Jan 28, 2019

the mount is a good way the internal call, or we can use a middleware call self

@micfan micfan closed this as completed Jan 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants