Slim framework: match routes starting with certain string - slim

Using Slim framework V2.6.3, is it possible to define a single route which captures all routes starting with certain string?
For example, I'd like to capture routes starting with apple-touch-icon, like these:
https://www.example.com/apple-touch-icon.png
https://www.example.com/apple-touch-icon-precomposed.png
https://www.example.com/apple-touch-icon-57x57.png
Thanks in advance

In Slim 2, you can define route conditions:
https://www.slimframework.com/docs/v2/routing/conditions.html

Related

Vapor 3: Route with arbitrary path segments

I'm working on a Vapor 3 app that uses the requesting path as the argument for the method that responds. For instance:
http://localhost:8080/monitor/some/test/path
That can be handled by a single endpoint, the monitor endpoint in this case, which would then ideally give me access to the rest of the URL, /some/test/path.
I've composed a route in Vapor that doesn't work using wildcard variables, and tried the group mechanic as described in the docs, to no avail. My expectation from using other web frameworks is that something like "/monitor/*" should do the job but I can't find anything in the documentation to suggest it.
Any assistance would be appreciated!
If you want to match any single path parameter, use the any path component. If you want to match any number of path parameters, use the all path component.
For example, if I register a route with these path components:
"service", any, "api", "users"
It will match these routes:
/service/v1/api/users
/service/caleb/api/users
But it won't match these:
service/v1/beta/api/users
service/v1
However, if you use the all component, like this:
"service", "api", all
You can match any of the following:
/service/api/v1
/service/api/v1/users/caleb
But not /service/api.

How to add query parameter to routes in Lumen?

I am trying to know how to add query parameters to routes in Lumen
this is an example of a route I created
$app->get('/product/{apikey}','ProductController#getProduct');
This works when I use
http://api.lumenbased.com/product/10920918
but I would like to use it like this
http://api.lumenbased.com/product/?apikey=10920918
I tried this
$app->get('/product/?apikey={apikey}','ProductController#getProduct');
But this gives me MethodNotAllowedHttpException
I would like to know how to write routes with query parameters in Lumen ?
Just do:
$app->get('/product','ProductController#getProduct');
and use:
$request->get('apikey')
in the ProductController#getProduct function.
(That said, validating an API key is better done via middleware...)

RESTFUL URLS in rails?

Hi I'm building REST api for an app, I have a requirement in URL
such that url should be something like this e.g
www.abc.com/api/param1/value1/param2/value2/param3/value3.... and so on
There are cases
case: The number of params are not limited it can change frequent
if today it is something like this
www.abc.com/api/param1/value1/param2/value2/param3/value3
tomorrow it can be like this
www.abc.com/api/param1/value1/param2/value2/param3/value3/param4/value4
Is there a configuration where once you configure the url pattern
and every thing go smooth
and in conrtoller params should contain this kind of key-value pair
{ "param1" => "value1","param2" => "value2","param3" => "value3"...and so on }
any suggestion !! how to achieve this ??
If your params are not fixed you can use wildcard in routing
for e.g
get 'items/list/*specs', controller: 'items', action: 'list'
def list
specs = params[:specs] # e.g, "base/books/fiction/dickens" #split it and place in a hash
end
Rails routing provides a way to specify fully custom routes with static and dynamic segments as explained in the Rails Routing Guide.
Your requirement should be achievable with
get '/api/param1/:param1/param2/:param2/...', to: 'controller#action'
You can use route scoping for this particular kind of problem . In other way it is nested routes
More details : http://guides.rubyonrails.org/routing.html#nested-resources
This is a example,
GET /magazines/:magazine_id/ads/:id/edit ads#edit
return an HTML form for editing an ad belonging to a specific magazine
I think this would be helpful for you.

Mojo Routes: Handle asorted tags in url

I am building a Mojo app to replace a vanilla mod_perl application.
The app currently handles url structures like:
/
/type/bold/
/keyword/hello/
/audience/all/
/type/bold/keyword/hello/
/keyword/hello/audience/all/
/keyword/hello/type/bold/audience/all/
/audience/all/type/bold/keyword/hello/
key/value pairs in the URL, that can exist in any order.
I am looking for a way to handle that without simply making a route for every permutation of tag, as that gets repetitive even after 3 different types of tags
In that case you should probably just make a route that matches everything and parse the url yourself.

Zend framework routing params

I have several routes defined in my application.
When route A is matched and I assemble an URL using route B without resetting, it does not include the current request parameters.
Is there an easy way to include all the request parameters when assembling an URL via a different route than the current route?
I did have a look at Zend_Controller_Router_Rewrite->useRequestParametersAsGlobal, but this will (obviously) also include the request parameters when reset = true
You could try the following.
$oldParams = $this->_getAllParamas();
unset($oldParams['module']);
unset($oldParams['controller']);
unset($oldParams['action']);
Pass
array_merge(array('new'=>'param'),$oldParams)
to your URL view helper.