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

Endpoint API:‌ Support octet-stream Media-type For Multipart Form Fields #2746

Open
khajavi opened this issue Mar 26, 2024 · 2 comments
Open
Labels
💎 Bounty enhancement New feature or request

Comments

@khajavi
Copy link
Member

khajavi commented Mar 26, 2024

I expect to have binary form fields to upload files in the Endpoint API using the octet-stream media type, but currently, the Endpoint API doesn't support such media type and throws an exception.

import zio._
import zio.http._
import zio.http.endpoint.Endpoint

object MultipartFormDataEndpointExample extends ZIOAppDefault {
  def run =
    Server
      .serve(
        Endpoint(RoutePattern.POST / "books")
          .in[String]("title")
          .in[String]("author")
          .in[Chunk[Byte]](MediaType.application.`octet-stream`, "file")
          .out[Unit]
          .implement(handler { (title: String, author: String, file: Chunk[Byte]) =>
            ZIO.debug("Handler called!")
          })
          .toHttpApp @@ Middleware.debug,
      )
      .provide(Server.default, Scope.default)
}

The console output when I run the above example:

import zio._
import zio.http._
import zio.http.endpoint.Endpoint

object MultipartFormDataEndpointExample extends ZIOAppDefault {
  def run =
    Server
      .serve(
        Endpoint(RoutePattern.POST / "books")
          .in[String]("title")
          .in[String]("author")
          .in[Chunk[Byte]](MediaType.application.`octet-stream`, "file")
          .out[Unit]
          .implement(handler { (title: String, author: String, file: Chunk[Byte]) =>
            ZIO.debug("Handler called!")
          })
          .toHttpApp @@ Middleware.debug,
      )
      .provide(Server.default, Scope.default)
}
@khajavi khajavi added the enhancement New feature or request label Mar 26, 2024
@jdegoes
Copy link
Member

jdegoes commented Jun 5, 2024

/bounty $150

Copy link

algora-pbc bot commented Jun 5, 2024

💎 $150 bounty • ZIO

Steps to solve:

  1. Start working: Comment /attempt #2746 with your implementation plan
  2. Submit work: Create a pull request including /claim #2746 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to zio/zio-http!

Add a bountyShare on socials

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💎 Bounty enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants