Skip to content
This repository has been archived by the owner on Mar 18, 2021. It is now read-only.

Allow resource controller endpoints to take query params as optional arguments #4

Closed
joeconwaystk opened this issue Aug 13, 2015 · 4 comments

Comments

@joeconwaystk
Copy link
Member

An endpoint could have optional arguments to automatically grab query parameters. These shouldn't impact routing or which handler gets the query parameters. A signature for a handler could then look like this:

@httpget
Future getThings({String location, String name}) {}

where name and location are names of query parameters (case insensitive) and if they exist, those arguments are populated.

@joeconwaystk
Copy link
Member Author

Implemented in 40dc2d8

@seanmavley
Copy link

Good!

Now, how does one construct the URL?
example.com/search?limit=5&page=10 how would that be constructed to be optional?

The routing doc here, https://aqueduct.io/docs/http/routing/ doesn't mention anything about query params routes construction

@EddieKamau
Copy link

By wrapping an argument in curly brackets:

@Operation.get()
Future<Response> foo({@Bind.query('name') String name}) async 
{}

This is documented here: http://aqueduct.io/docs/http/resource_controller/#optional-bindings

@evertonfoz
Copy link

evertonfoz commented Jun 20, 2020

@EddieKamau , when I use

@Operation.get()
Future<Response> foo({@Bind.query('q') String name}) async {}

and don´t send any query parameters, I receive the

The method '[]' was called on null.
Tried calling: []("q") #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)

Can you help me please?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants