Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Lots of changes here. Tuyau now has a system that's a bit like Ziggy. Basically, we can use the names of our routes defined in AdonisJS, but in the frontend. Let's start by listing the breaking changes:
Breaking Changes & Migration
You will first need to download the latest versions of
@tuyau/utils
@tuyau/core
and@tuyau/client
for everything to work correctly.The codegen file has changed location. It is now located in
.adonisjs/api.ts
. You will therefore need to change the import path of your client to access this new file.To initialise the client, you will now need to do the following:
As you can see, you first need to change the import path and the imported value. Next, you need to pass this
api
object as an argument to thecreateTuyau
function.Remember to re-generate your
.adonisj/api.ts
file vianode ace tuyau:generate
, and you should be fine for the rest.Features
Making Requests using the route name
If you want to use the names of the routes instead of paths, you can use the
$route
method. Of course this method is also fully typesafe :Generating URL from route name
If you need to generate the URL of a route using the route name, you can use the
$url
method. This method is pretty similar to Ziggy behavior :If you are used to Ziggy and prefer to have a
route
method instead of$url
, you can define a custom method in your client file pretty easily :Then you can use the
route
method in your frontend code :Check if a route exists
If you need to check if a route name exists, you can use the
$has
method. You can also use wildcards in the route name :