Passing data via URL

Hi there,

I’m creating an API and I’m wondering if there is any way to pass data via an URL with a post method for example add?name={name}&age={age}…
I don’t have much experience with API development, but I remember this URL thingy worked in Spring Boot.

Thanks in advance.

I am, by no means, an expert on this, as I am still learning. The best way to learn is to get involved and probably say something stupid :slight_smile: .

But, if you make the route a get route, you have access to the query parameters, you do not if you make the route a post route.

But, a quick google shows that you can access them with something like this:
$request->getParams()

In Slim 4 you can get the query parameters as an associative array on the Request object using getQueryParams() .

$params = $request->getQueryParams();
$value = $params['key'] ?? null;

http://www.slimframework.com/docs/v4/objects/request.html#the-request-uri

If you want to create a URL, you can use the RouteParser object using the 3rd parameter of the urlFor, fullUrlFor and relativeUrlFor method:

use Slim\Routing\RouteContext;

// ...

$routeParser = RouteContext::fromRequest($request)->getRouteParser();

$url = $routeParser->urlFor('my-route-name', [], ['name' => 'Max', 'age' => 18]);