Welcome to Trishul API Questions and Answers. Help and learn how to use it efficiently.
0 like 0 dislike
13 views
in Request by (570 points)
Hi developers, as all of us know that whenever we work on any restful backend. We have to deal with the path variables for example

/user/{username}
 

How to get this path variable in Trishul API?

1 Answer

0 like 0 dislike
by (570 points)
 
Best answer
Hi developers, as all of us know that whenever we work on any restful backend. We have to deal with the path variables for example

/user/{username}

We have created this endpoint to provide the user data to client after getting the username value from the client.

This endpoint provides the user data to the client. It takes one path variable username and then fetches the data from database and returns to the client.

In Trishul API, you can get this path variable from the $request object.

$username = $request->path()->get('username');

That's it. You will get the $username from the path variable and pass it to your logic.
by (570 points)
0 0
It returns null if the pathvariable doesn't exist. You can simple check the existence by another method.

$request->path()->has('username');

It returns true or false.
Welcome to TrishulAPI Q&A, where you can ask questions and receive answers from other members of the community.
...