Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 22:50
    scala-steward opened #4763
  • 16:53
    vasilmkd opened #4762
  • 16:32
    scala-steward opened #520
  • 14:26
    RafalSumislawski commented #4761
  • 13:21
    rossabaker milestoned #4761
  • 13:21
    rossabaker labeled #4761
  • 13:21
    rossabaker labeled #4761
  • 08:49
    vasilmkd commented #836
  • 08:36
    moonflow starred http4s/http4s
  • 06:32
    RafalSumislawski commented #4761
  • 03:48

    rossabaker on main

    Use a unique io runtime in Blaz… Shutdown the Blaze suite IO run… Merge pull request #4755 from v… (compare)

  • 03:48
    rossabaker closed #4755
  • 03:48
    rossabaker closed #4166
  • 03:46
    rossabaker commented #836
  • 03:15
    rossabaker commented #4761
  • Apr 18 22:14
    vasilmkd commented #836
  • Apr 18 19:42
    RaasAhsan commented #4737
  • Apr 18 19:32
    L7R7 closed #4760
  • Apr 18 19:32
    L7R7 commented #4760
  • Apr 18 19:30
    vasilmkd commented #4755
Carlos Verdes
@carlos-verdes
For example I want to add a Location header on Created status 201, the Location has a url which depends on the resource right?
however I can't implement that with current EntityEncoder trait
    new EntityEncoder[F, RestResource[R]] {
      override def toEntity(resource: RestResource[R]): Entity[F] = EE.toEntity(resource.body)

      override def headers: Headers = Location(resource.uri)
    }
you can see the last line... I don't have resource available
I only can create a myme type header... which also would be static
and in my case I have a wrapper so I need also to generate the mime type on runtime
so I expect to have something like this on the headers function
override def headers(resource: RestResource[R]): Headers = Headers.of(Location(resource.uri), `Content-Type`(resource.mediaType))
Carlos Verdes
@carlos-verdes
I would use your Entity case class but I miss things like links, which is a core part of my design
so I create this RestResource wrapper which has the resource body, uri, links etc
Jack Viers
@jackcviers
Figured it out -- I was trying to wrap auth routes, but that won't work because of the context request. After passing the entire route list (including the failthrough routes) and ending with .orNotFound I could wrap them in the UrlFormLifter.
Ross A. Baker
@rossabaker
@jackcviers :+1: Sorry that was a struggle. I was soccering all day yesterday and in meetings all morning.
Jack Viers
@jackcviers
LOL. I was messaging you on the way to and from our old-man's pickup soccer game.
Ross A. Baker
@rossabaker
@carlos-verdes This is actually the oldest open issue we have, and I recently revived it: http4s/http4s#146
I'm just coaching 11-year-olds now. :laughing:
Jack Viers
@jackcviers
I wish my daughter liked it enough to play. But she's hardcore gymnast/dancer, so no coaching for me.
Ross A. Baker
@rossabaker
@carlos-verdes You can see some history there of why we don't have that, but I think it's something we should think about changing. I think we can make it work in a way that doesn't obliterate static analysis.
I topped out at about U8, but my kids wanted to play. I volunteered to stripe the fields, ended up being handed a clipboard, and have been coaching for a decade. I just have to learn at least as fast as she grows up!
It's a great game, and I now regret not playing more before decrepitude set in.
Jack Viers
@jackcviers
I played organized soccer until I was 24. I still love to play, but I've definitely lost a few steps as I near 40.
Carlos Verdes
@carlos-verdes
@rossabaker let me read the issue first to get full context
I see you cover some of my concerns
you cover the 2 scenarios I would like to cover
1 - be able to generalize over Content-Type --> For example I want to create my custom vnd type
Content-type: application/vnd+company.category+json
Carlos Verdes
@carlos-verdes
For this case we don't need to get the body at runtime, we can just use a trait like this:

trait HeaderGenerator[R] {

  def headers[R]: Headers
}

new EntityEncoder[F, R] {
  override def headers(implicit hd: HeaderGenerator[R]): Headers = hd.headers[R]
Carlos Verdes
@carlos-verdes
but it may be complex to use I think
the other scenario needs access to the body:
2 - be able to generate a Header like Location --> if we don't want to apply this header on EntityEncoder at least provide another Type Class
... forget about last point
I'm just realising this should not be part of a generic encoder
Location is only present on 201 CREATED but it's not necessary on a 200 OK
also the resource could be part of a search result so it has no sense to have this header
Location Header should be applied only when creating our routing logic...
test example
      case request @ POST -> Root / "mocks" =>
        for {
          mockRequest <- parseRequest[IO, Mock](request)
          savedMock <- store[Mock](request.uri, mockRequest)
          fetchedMock <- fetch[Mock](savedMock.uri)
        } yield Created(fetchedMock.body, Location(fetchedMock.uri))
Carlos Verdes
@carlos-verdes
I also want to add on top of last code Link headers
with uri + links + body I have almost all I need for REST API´s
I don't know if you thought to add this as part of HTTP4S
another element really useful in the ETags
I'm creating something like this as part of my business model
  case class RestResource[R](uri: Uri, body: R, link: Link)
this can be an extension of Entity, something like:
case cass EntityResource(
    uri: Uri, 
    body: EntityBody[F], 
    length: Option[Long], 
    links: Link)
Carlos Verdes
@carlos-verdes
then we can generate headers like Link, Location, etc
Ross A. Baker
@rossabaker
(Sorry, I have lots of meetings today.)
The classic example of having a runtime encoder is multipart: we need access to the runtime value to be able to put the boundary parameter on the Content-Type.
Another one is files: runtime value of the file gets you the name gets you the Content-Disposition.
These are things we can't do with the current encoders. There's a special function somewhere to set a multipart entity, because the content-type isn't right without that second step.
rnd4222
@rnd4222_gitlab
What do you guys think about FLoC?
As a developers of server software you have the power to disable it by default by setting approriate header.