Skip to content

Extend path parameter support #661

Description

@diego-aquino

Scope

@zimic/http

Prerequisites

  • I confirm that none of the open issues match my proposal
  • I confirm that my proposal is not yet available in the latest version of Zimic (see the documentation and the releases)

Type

Adds a new behavior

Compatibility

  • This is a breaking change

Context

Currently in @zimic/http, path parameters are fully inferred from the pathname. As an additional feature, we could support custom path parameter declarations, similarly to searchParams.

import { type HttpSchema } from '@zimic/http';

interface User {
  id: number
  username: string;
}

interface RequestError {
  code: string;
  message: string;
}

type Schema = HttpSchema<{
  '/users/:userId': {
    PATCH: {
      request: {
        pathParams: { userId: User['id'] };
        headers: { authorization: string };
        body: Partial<User>;
      };
      response: {
        204: {};
        400: { body: RequestError };
      };
    };
  };
}>;

Notes

  • Path params should continue to be inferred as before. Declaring a custom pathParams should only override the default params.

Feature description

  • [http] Support pathParams in request schema declarations
  • [interceptor] Handle custom pathParams in HTTP request handlers
  • [fetch] Handle custom pathParams in fetch clients

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions