Effect CommunityEC
Effect Community12mo ago
4 replies
Florian

Expressing Base64 Encoding and Headers in HttpApi Module

I have an API endpoint that returns a PDF as a base64 string. Our old service uses the following OpenAPI spec:

"/invoices/{invoiceId}/receipt": {
  parameters: [
    {
      $ref: "#/components/parameters/invoiceId",
    },
  ],
  get: {
    operationId: "getPreviewReceipt",
    responses: {
      "200": {
        content: {
          "application/pdf": {
            schema: {
              type: "string",
              format: "base64",
            },
          },
        },
        headers: {
          "Content-Disposition": {
            schema: {
              type: "string",
              example: "attachment; filename='name.pdf'",
            },
          },
        },
      },
    }
  }
}


Can this be expressed with the HttpApi module? Currently I have this

class InvoicesGroup extends HttpApiGroup.make("invoices")
  .add(
    HttpApiEndpoint.get("getPreviewReceipt", "/invoices/:invoiceId/receipt")
      .addSuccess(
        S.String.pipe(
          HttpApiSchema.withEncoding({
            kind: "Text",
            contentType: "application/pdf",
          }),
        ),
      )
      .setPath(S.Struct({ invoiceId: InvoiceId })),
  ) {}


But it lacks informattion regarding the base64 encoding as well as the respoonse headers.
Was this page helpful?