Comments (9)
I'll take a look ASAP. Thanks for reporting.
from raisin.
Maybe I misunderstand how route_param
is supposed to be used, but aren't you supposed to pair route_param
with a params()
call describing the route param like this?
params( requires('locale', type => Locale, desc => '...') )
route_param locale => sub {
...
};
from raisin.
To me, its not clear how route_params can be mixed with query params... but saying that the above code works as described in 0.86 and doesnt in 0.87. But strangely, it routes correctly in 0.87 but doesnt populate the $_[0] with a hashref of parameters.
If i have misinterpreted the documentation and somehow relied upon non-intentional behaviour i am happy to change my code. But for now i have Raisin pinned to 0.86 in my cpanfile
from raisin.
Part of the problem is that nested route_param
was broken badly in 0.86 and prior, in that the inner route_param
would blow away all param definitions of previous route_param
declarations.
This was fixed in 0.87.
I suspect this is what you need for 0.87:
resource 'etd' => sub {
summary 'Get an estimate';
desc 'Estimated Time of Delivery';
params( requires( 'locale', type => Locale, desc => 'Locale (AU/NZ)' ) );
route_param 'locale' => sub {
params( requires( 'postcode', type => PostCode, desc => 'Post Code' ) );
route_param 'postcode' => sub {
...
# query param style
before_validation \&fix_material;
params(
requires( 'material', ... );
optional( 'orderdate', ... );
);
summary 'GET one or more products via material code as query parameter';
get \&guess_etd;
# url path style
params( requires( 'material', ... ) );
route_param 'material' => sub {
summary 'GET a single product via material code in url';
params( optional( 'orderdate', ... ) ):
get \&guess_etd;
}; # route_param 'material'
}; # route_param 'postcode'
}; # route_param 'locale'
}; # resource 'etd'
And as a nice benefit you don't have to repeat the postcode
and locale
params for every internal endpoint.
But per the raisin docs, preceding the route_param
with a params()
call that describes the route param seems to be the recommended way to deal with route params.
from raisin.
Ok this seems to work but has the annoying side effect that previously if the route_param value type didnt match the type it would return 400. Where as now it returns a 404. I am guessing this is due to failing to match causing it to not route past the handler code.
from raisin.
That indeed is not fixed yet. It's on my roadmap.
from raisin.
Just out of curiosity, because I did not find it anywhere, and before digging into the code, I would ask: How do you access the postcode
and locale
variables in guess_etd
?
From what I see while playing around with it is that the get sub's first param is only returning the params on the level it is defined...
from raisin.
that would be something like:
get sub {
my $params = shift;
$params->{postcode};
$params->{locale};
$params->{...};
}
Where $params
is a hashref
to all the parameters parsed by:
Line 12 in 5f77df3
The problem here must be that nested path arguments are not stored properly and/or got overwritten somewhere inside that function:
Line 102 in 5f77df3
This would be the patch which introduced the issue: 06d50a9
from raisin.
my bad, I messed up the params
block. thanks!
I have found some examples I was looking for in the test cases (which I didn't think of looking at).
from raisin.
Related Issues (20)
- Optional params that fail type constraints do not return "Invalid Parameters" response.
- Encoder/Decoder are unable to cope with UTF-8 / wide characters.
- t/unit/plugin/swagger.t fails (with Type::Tiny 1.006000?) HOT 5
- Feature Request: Swagger schemes
- $count in SYNOPSIS HOT 1
- Please include VERSION in all modules HOT 4
- Authentication module in Raisin HOT 3
- Disable the route extension. HOT 2
- Ideas to discuss HOT 4
- Improvement: allow swagger to reside behind a reverse proxy
- Request for clarification HOT 3
- Reverse proxy not done correctly HOT 7
- escaping colon in resource path
- Presenting DBIx::Class::ResultSet does not work correctly HOT 6
- please tag recent CPAN releases in git HOT 1
- Regex check in Raisin::Entity flags numbers as strings for JSON::XS
- Bump version to 0.94 please? HOT 3
- route_param regex is broken by R::Routes::Endpoint::_build_regex if contains quantifiers...
- Participate in hacktoberfest?
- question: can Raisin handle file uploads ? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from raisin.