Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shortcomings with client $url method #1464

Open
renzor-fist opened this issue Sep 15, 2023 · 6 comments
Open

Shortcomings with client $url method #1464

renzor-fist opened this issue Sep 15, 2023 · 6 comments
Labels
enhancement New feature or request.

Comments

@renzor-fist
Copy link
Contributor

renzor-fist commented Sep 15, 2023

What is the feature you are proposing?

Hi @yusukebe, I recently added this feature. #1384

However, the URL type doesn't include the route method (e.g. GET, POST, ...), a critical part of the shape of a route. For example, when mocking responses using this new $url method:

const fetchMock = getMiniflareFetchMock()

const { hostname, pathname } = hc<AppType>('http://localhost:3000').v1.deployment.$url()

fetchMock
        .get(hostname)
        .intercept({
          method: "POST", <-- there's no way to get this from the $url 😢 
          path: pathname,
        })
        .reply(200)

Wanted to get your thoughts on possibly improving $url to include method, or possibly adding a $request method that returns the Request type

const { method } = hc<AppType>('http://localhost:3000').v1.deployment.$request()
console.log(method) // POST

Interested in your thoughts on this. I'd be happy to make any desired changes.

@renzor-fist renzor-fist added the enhancement New feature or request. label Sep 15, 2023
@yusukebe
Copy link
Member

Hi @renzor-fist

This could be a difficult challenge.

const { method } = hc<AppType>('http://localhost:3000').v1.deployment.$request()

I think this method is difficult because there may be more than one method in /v1/deployment, such as GET and POST.

@yusukebe
Copy link
Member

cc: @ehagishi

What do you think about it?

@hagishi
Copy link
Contributor

hagishi commented Sep 17, 2023

Hi.

Have you considered extending the path like this?

const { method, url } = hc<AppType>('http://localhost:3000').v1.deployment.$get.$request()

If you just want to test with the hc client, using #1451 would be the simpler approach, in my opinion.

@renzor-fist
Copy link
Contributor Author

Hello gentlemen,

Apologies for the delayed response. @yusukebe I had overlooked this and apologize for the situation.

@hagishi has a good approach that I will attempt to replace $url with. Is it OK to replace this method, or should I only add $request for backwards compatibility?

@renzor-fist
Copy link
Contributor Author

Hi @yusukebe and @hagishi, below you will find an implementation of the $request method

#1514

@yusukebe can you help me with writing a type for the $request method? It is unfortunately beyond my grasp of the Typescript language.

@yusukebe
Copy link
Member

@renzor-fist

Thanks!

You are right, there is a TypeScript “type" issue. I just tried a little and could not infer it well. It may be very difficult or impossible.

@hagishi Do you have any idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request.
Projects
None yet
Development

No branches or pull requests

3 participants