Skip to content

Typescript client can't work with query params #4

Description

@hascommitissues

According to the https://docs.servicestack.net/api-design, I create my model like this:

[Route("/my-request")]
public class MyRequest : IGet, IHasQueryParams, IReturn<MyResponse>
{
  public Dictionary<string, string>? QueryParams {get; set;}
}

Now I generate a Typescript DTO:

// @Route("/my-request")
export class MyRequest implements IReturn<MyResponse>, IGet
{
    public queryParams?: { [index:string]: string; };

    public constructor(init?: Partial<MyRequest>) { (Object as any).assign(this, init); }
    public getTypeName() { return 'MyRequest'; }
    public getMethod() { return 'GET'; }
    public createResponse() { return new Array<MyResponse>(); }
}

Now, in my code, I send data like this:

    async getData(
        param1: string,
        param2: string,
        param3: string
    ): Promise<MyResponse> {
        return await this.client.get(
            new MyRequest({
                queryParams: { param1, param2, param3 },
            })
        );
    }

It generates the request like this:

https://localhost:5003/api/MyRequest?queryParams=%5Bobject%20Object%5D

Expected:

https://localhost:5003/api/MyRequest?param1=...&param2=...&param3=...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions