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

HTTP interceptor request path params #87

Closed
2 tasks done
diego-aquino opened this issue Feb 23, 2024 · 0 comments · Fixed by #140
Closed
2 tasks done

HTTP interceptor request path params #87

diego-aquino opened this issue Feb 23, 2024 · 0 comments · Fixed by #140
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@diego-aquino
Copy link
Member

diego-aquino commented Feb 23, 2024

  • First-class support to path params schemas
  • Infer the default path param schema from the path. Proof of concept:
    type Path = '/groups/:groupId/users/:userId';
    
    type RecursivePathParamsRecord<Path extends string> =
      Path extends `${infer _Prefix}:${infer ParamName}/${infer Suffix}`
      ? { [Name in ParamName]: string } & PathParamsRecord<Suffix>
      : Path extends `${infer _Prefix}:${infer ParamName}`
        ? { [Name in ParamName]: string }
        : {};
    
    type PathParamsRecord<Path extends string> = Prettify<RecursivePathParamsRecord<Path>>;
    
    type PathParams = PathParamsRecord<Path>;
    // {
    //   groupId: string;
    //   userId: string;
    // }
@diego-aquino diego-aquino added the enhancement New feature or request label Feb 23, 2024
@diego-aquino diego-aquino modified the milestones: v0.4.0, v0.5.0 Feb 23, 2024
@diego-aquino diego-aquino modified the milestones: v0.5.0, v0.4.0 Apr 12, 2024
@diego-aquino diego-aquino self-assigned this Apr 12, 2024
@diego-aquino diego-aquino modified the milestones: v0.4.0, v0.8.0 Apr 12, 2024
@diego-aquino diego-aquino removed their assignment Apr 12, 2024
@diego-aquino diego-aquino removed this from the v0.8.0 milestone Apr 12, 2024
@diego-aquino diego-aquino added this to the v0.5.0 milestone Apr 20, 2024
@diego-aquino diego-aquino self-assigned this May 4, 2024
@diego-aquino diego-aquino modified the milestones: v0.5.0, v0.6.0 May 11, 2024
diego-aquino added a commit that referenced this issue May 25, 2024
### Features
- [#zimic] Added support to inferred path params from dynamic URLs.

```ts
interceptor.get('/users/:id').respond((request) => {
  console.log(request.pathParams.id) // '1'

  return {
    status: 200,
    body: users[0],
  };
})

await fetch('http://localhost:3000/users/1'), { method: 'GET' });
``` 

Closes #87.
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

Successfully merging a pull request may close this issue.

1 participant