Skip to content

Simplify management of query parameters #448

@darrachequesne

Description

@darrachequesne

Hi!

If I understand correctly, one can already extract the query parameters with setRequestCallback():

// note: async is needed here, else an "Uncaught TypeError: this.requestHandler(...).then is not a function" exception is thrown
h3Server.setRequestCallback(async ({ header }) => {
  const url = new URL(header[":path"], "https://example.com");
  if (url.pathname === "/my-path/") {
    header[":path"] = url.pathname;

    // option 1: added on the header object
    header[":query"] = url.searchParams;

    return {
      path: url.pathname,
      header,
      status: 200,
      // option 2: added on the userData object
      userData: {
        query: url.searchParams
      }
    }
  }
  return { status: 404 };
});

Is that right? In that case, do you think it would make sense to include them directly on the HttpWTSession?

Thanks in advance.

Related: #279

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