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

feat: callable endpoints and authenticators #6

Merged
merged 8 commits into from
Mar 10, 2021
Merged

Conversation

adamcooke
Copy link
Contributor

@adamcooke adamcooke commented Mar 9, 2021

This adds the ability to define action attributes as methods to allow far greater extensibility. The old technique of definition the action as a block still works but will be deprecated.

  • Ensure the using a call method works
  • Update all documentation
  • Add tests for the new style of class definition
class MyEndpoint < Rapid::Endpoint
  
  # Define metadata as normal
  description 'Something about this endpoint'
  argument :name, :string, required: true
  field :name, :string

  # Instead of defining `action`, just add a `call` method.
  def call
    # Do something here. Same access to things like `request`, `response`
    # and other helpers as before.
  end

  # You can now use private methods and/or import other modules into this
  # this class to use their methods.
end

Exactly the same as above also applies to Authenticators using the same syntax because they also have an action option.

Before, endpoints wouldn't usually be defined in their own class and would just be defined within a controller. There is no requirement for an endpoint to be within a controller if using this method (although you can if you want to).

# When defining routes, you can just reference the endpoint directly
get 'something', endpoint: MyEndpoint

# If you do want to use a class-based endpoint in a controller, you can just list that
class MyController < Rapid::Controller
  endpoint :something, MyEndpoint
end

# and then use it as normal in routes...
get 'something', controller: MyController, endpoint: :something

@adamcooke adamcooke changed the title feat: callable endpoints feat: callable endpoints and authenticators Mar 9, 2021
@adamcooke adamcooke marked this pull request as ready for review March 10, 2021 14:38
@adamcooke adamcooke merged commit 9aa0b55 into master Mar 10, 2021
@adamcooke adamcooke deleted the callable-classes branch March 10, 2021 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant