SLIM PHP Routing Type - php

I'm working on updating my Slim API and wanted to add the ability to define the type of response for a route within the routes url. Similar to how Reddit or Rails does it where you can add a .html,.json, or .xml to a route and have that route return the proper formatted data. Below is a Reddit example of one route being able to return a json,xml, or html response by changing the ending to whatever response type.
http://www.reddit.com/r/ObjectiveC.json
Is this something I will have to do manually with middleware parsing every route or does Slim have this built in? Any help would be greatly appreciated.
Thanks

What you're looking for isn't natively available, but you might want to look at the ContentTypes Middleware in the Slim-Middleware repo. I think that'll get you close to where you need to go, although the type is detected via the content type header via \Slim\Http\Request::getMediaType.

Related

Shopware PWA custom route

I've create a custom Store route inside Shopware 6 as a plugin.
It shows up in the store-api/_info/swagger.html url.
What is does is it return an array with static text for now.
Now is my question, how would i call this url inside the pwa with vuestorefront.
I created a page inside src/pages but i cant wrap my mind around how to call the url to ge the data.
Do i need to specify the whole url in the axios? I cant find any documentation about this.
Thanks in advance!
You approach so far is correct.
Create a new Store API route to fetch data from Shopware
Create a new Nuxt page by creating a page in src/pages.
Now we only need to connect the dots.
Nuxt pages are simply Vue components, so you can use the invokePost or invokeGet methods from the shopware-6-client package to call your custom endpoint.
You could also use axios to do it, but then you'll need to handle additional parameters (e.g. passing the correct sw-context-token or sw-access-key manually.

How can I post data from a raw Php page to a Laravel controller?

I have a laravel project with a raw (. php) page. On this page is a form. I would like to post this form from the raw php page to a controller I have. How, if possible can I achieve this?
So after looking around online, I found the answer to be that I needed to use API routes. The file is located in Routes/api.php. One can add their routes there so requests from outside the Laravel application can be sent in. Simply add your route there and corresponding action for said route.

Routing with laravel

So I am working on a project and I have decided to use php laravel framework, but when it comes to things like creating a new page and dealing with page redirects etc, am I right in thinking that all these will be handled in the route/web.php file so all the pages for my application will be defined in the route along with the view ?
I was thinking what if my application grows to have dozens of pages is it best practice to define each one on the route or are there better ways to handle this?
Yes, the best way to do routing is laravel to have each route for . each page, the only exception is when you have dynamic routes, for example, if you have a route that checks for users id or category for some product etc and it looks something like this Route::get("/product/{$category_id}","FrontController#methodForGetingProduct").
And later in Controller, you define what will you send and receive of the information and what view should be returned.
you can follow this type routing .......

Change Curl URL in Swagger UI

I'm developing a new API using Slim Framework (v3).
I'm trying to integrate this API with Swagger UI, but when I click "Try it" button, Swagger generates the following link.
Example link:
http://localhost/api/public/contact?param1=1&param2=2param3=3
It's correct if I don't use Slim, but a link for Slim API is like:
http://localhost/api/contact/1/2/3
What I want is that Swagger use a link to Slim API, how can I do to achieve that? I can't find a way to "translate" the link format.
I'm using Swagger-php for comments (annotations).
I hope you can help me. Thanks.
You have a couple different options.
First Swagger-ui won't show that link unless it's defined somewhere (i.e the basePath attribute) or left undefined. It sounds like there's something missing there.
Next, you can always override the basePath in your API like such:
window.swaggerUi.api.setBasePath('/api');
Which should take away the /api/public section.
It's a little difficult to debug without seeing your JSON or YAML swagger definition but those two techniques should get you over the hump.

React js with Laravel (5.1): Removal of the URL hash causes laravel router to kick in and fail

I have set up a simple app for now using ReactJS for the frontend and Laravel(5.1) for the backend.
All is OK but I woudl like to make the URLS look normal, as in the removal of the '/#' from the URL.
So
example.co.uk/#/about
becomes
example.co.uk/about
This is not an issue as I achieve this, but when I do it activate it, then the Laravel routing kicks in and flags a route error.
Is it possible to prevent Laravel form activating / doing this so that ReactJS takes over and works.
If so it would also be nice, so that if a Laravel route is set / wanted then it does use that one.
EG: These are ReactJS routes that would have used the '/#'
example.co.uk/about
example.co.uk/details
example.co.uk/listings
Then if I got to the following URL's then they are controlled by Laravel's routing?
example.co.uk/api/...
example.co.uk/admin/
Thanks
You need a catch-all route that will execute the same main controller action regardless the URL. Add the following to your routes.php
Route::get('{path?}', 'Controller#action')->where('path', '.*');
This way all URLs will go to Controller#action, that should display the base view for your application - the one that runs the ReactJS application.

Categories