Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jun 22 06:59
    agboom commented #794
  • Jun 22 06:58
    agboom commented #794
  • Jun 21 07:17
    codecov[bot] commented #842
  • Jun 21 07:11
    julienrf commented #842
  • Jun 21 07:11
    julienrf commented #842
  • Jun 21 07:08
    codecov[bot] commented #842
  • Jun 21 07:08
    Fristi synchronize #842
  • Jun 21 06:59
    Fristi commented #842
  • Jun 21 06:57
    codecov[bot] commented #842
  • Jun 21 06:56
    Fristi synchronize #842
  • Jun 20 23:42
    codecov[bot] commented #839
  • Jun 20 23:34
    codecov[bot] commented #839
  • Jun 20 23:34
    mleclercq synchronize #839
  • Jun 20 23:21
    codecov[bot] commented #839
  • Jun 20 23:21
    mleclercq synchronize #839
  • Jun 20 23:00
    codecov[bot] commented #839
  • Jun 20 22:51
    codecov[bot] commented #839
  • Jun 20 22:51
    mleclercq synchronize #839
  • Jun 20 22:47
    codecov[bot] commented #839
  • Jun 20 22:47
    mleclercq synchronize #839
Julien Richard-Foy
@julienrf
@LeifW maybe you’ll find an answer here: https://www.youtube.com/watch?v=yEYPf44rS2U
Leif Warner
@LeifW
I guess doing traverse + traverse works.
For some reason sequence on the result wasn't working at all, but traverse does work.
Leif Warner
@LeifW
It seems more common to be to have the Either on the outside - because I do some validation before deciding whether to immediately return 400 or kick off the Future IO action... but traverse works.
Georgi Krastev
@joroKr21
In that case you can do the traverse already in the validation step :thumbsup:
Leif Warner
@LeifW
If I have a lot of different response codes I might want to return, e.g. 200 or 201 or 204 or 400 - does that mean I just nest a bunch of Eithers?
Alec Theriault
@harpocrates
If you've got a lot of possible response codes, you can xmapover the ResponseEntity to turn your nested Either's into some more palatable sealed trait that better fits your domain. That way, the Either stuff shows up only in the body of the endpoint definition and the type of the whole endpoint is in terms of your domain.
Dominic Egger
@GrafBlutwurst
out of curiosity why is QueryString an invariant partial functor? when is there a need to translate from decoded params to query string?
Julien Richard-Foy
@julienrf
@GrafBlutwurst Client interpreters encode params into a query string
Dominic Egger
@GrafBlutwurst
ahhh right makes sense. thanks!
Dominic Egger
@GrafBlutwurst
how does the JsonEntitiesFromEncodersAndDecoders differ from JsonEntitiesFromCodec http4s seems to have the latter but an endpoint serving OpenApi seems to use the former?
Julien Richard-Foy
@julienrf
FromEncodersAndDecoders only requires an Encoder to be available, whereas FromCodec requires both an Encoder and a Decoder. In the case of OpenApi, we only have an Encoder so far, that’s why we still have these JsonEntitiesFromEncodersAndDecoders traits
Dominic Egger
@GrafBlutwurst
ahhh then the AndDecoders bit is slightly confusing i suppose. but that makes a lot of sense. but the algebra is not available for http4s server it seems? or is my code discovering just broken?
hmm I think i need a flavour of jsonResponse that does not require a Codec in that case
Julien Richard-Foy
@julienrf
indeed, we miss the http4s version of the interpreter JsonEntitiesFromEncodersAndDecoders
(it should be easy to add, though)
Leif Warner
@LeifW
Is there a way of turning Paths into nice strings - to refer to from the documentation of other routes?
Julien Richard-Foy
@julienrf
@LeifW I think all the client interpreters should be able to do that. The play-server and xhr-client interpreters have dedicated methods for that. Which interpreter do you use?
caeus
@caeus
Quick question. Does Endpoints4s support xxx-urlencoded-form content type? if so, how?
Julien Richard-Foy
@julienrf
@caeus There is no out-of-the-box support but it would be easy to add even as a third-party extension (without changing the library itself)
Julien Richard-Foy
@julienrf
Hello @/all, I have added an “Adopters” section to the README, I would appreciate if you could give me a few organization names I can add to the list :smile: https://github.com/endpoints4s/endpoints4s/blob/master/README.md#adopters
Dominic Egger
@GrafBlutwurst
1 reply
Leif Warner
@LeifW
@julienrf Using the akka http interpreter.
1 reply
In the routes, I've been using Either and having it Left(Invalid(...)) on the failure case - noticing that Invalid's the failure case of Validated... wondering if I should be having the routes return Validated instead of Either?
2 replies
Julien Richard-Foy
@julienrf
@LeifW Actually, I just realized that you want to be able to do that in the documentation, not necessarily in the server
So, this is something we could add to the openapi interpreter maybe, and all the server interpreters would benefit from it
I’ve just opened #728 to implement it in the Akka HTTP server interpreter, though
Leif Warner
@LeifW
Nice, thanks!
In the error handlers, you have access to the Throwable... I'm wondering if there's a spot that has access to both that Throwable, and the request (at least the name of the endpoint that was called)?
I'd like to log unexpected Throwables, but was thinking it'd also be nice to log the request that lead to that exception being thrown...
Julien Richard-Foy
@julienrf
@LeifW handleServerError returns a StandardRoute, so you can extract request information in the returned route.
Julien Richard-Foy
@julienrf
Hey @/all, I have just cut a new release: https://github.com/endpoints4s/endpoints4s/releases/tag/v1.3.0 thank you all for your contributions!
Adriaan Groenenboom
@agboom
Hi, does anyone know if it is possible to define an endpoint with a url that ends with a slash (or optional slash)? I tried the following but it still gave a 404 on localhost/foo/ (but not on localhost/foo):
endpoint(
  method = Get,
  url = path / segment[String]() / "",
  response = textResponse,
)
Adriaan Groenenboom
@agboom
(this is with the Akka HTTP backend btw)
Julien Richard-Foy
@julienrf

@agboom I think this use case is not covered at the moment. You may want to introduce something like the following:

def trailingSlash[A](path: Path[A]): Path[A]

Which you could use as follows:

endpoint(
 method = Get,
  url = trailingSlash(path / segment[String]()),
  response = textResponse
)
And you would have to figure out the implementations for server, client, and openapi interpreters, according to your usage
Adriaan Groenenboom
@agboom
Thanks for the pointer @julienrf, I was indeed thinking the same. I'll try to implement it and open a PR if I succeed
Julien Richard-Foy
@julienrf
That would be great, thanks!
Let me know if you need more help
Adriaan Groenenboom
@agboom
I'm looking into the Akka HTTP server interpreters and was wondering: what's the thought behind Path.validateUrl calling Url.validate? It seems that only the path passed to validateUrl is actually validated, but the query is ignored. Is that intentional?
Link to code: https://github.com/endpoints4s/endpoints4s/blob/154e7ce630f284056f8c9ba3d8f302e326c9d696/akka-http/server/src/main/scala/endpoints4s/akkahttp/server/Urls.scala#L23
3 replies
Also: I think the (optional) trialing slash I'm trying to implement will involve a change in Url.directive in the server interpreter, because Directive.Segments does not match trailing slashes: https://github.com/endpoints4s/endpoints4s/blob/154e7ce630f284056f8c9ba3d8f302e326c9d696/akka-http/server/src/main/scala/endpoints4s/akkahttp/server/Urls.scala#L64
The Scaladoc string of Directives.Segments says: "If the path has a trailing slash this slash will not be matched."
2 replies
Adriaan Groenenboom
@agboom
If I run sbt test on the latest commit, some tests appear to fail (only due to exceptions, not assertions). Is that expected behavior? Here are the logs: https://pastebin.com/mM7ykeav
In short, there's a timezone error (probably because of the tz config on my local machine?), a ServerListenException on port 9000 (I checked if the port was in use, but it wasn't) and a generic Exception with "Something went wrong" followed by a dead letter warning (but that appears to be part of testing the exception flow, so that's expected)
Julien Richard-Foy
@julienrf
@agboom, the JS tests need jsdom to be installed locally ($ npm install jsdom). The ServerListenException is not expected, and I think we also get it spuriously on the CI, so this is something we need to fix, and the “Something went wrong” is not an actual test failure, it’s part of the expected test execution.
1 reply
Adriaan Groenenboom
@agboom

@julienrf I think I found a fairly simple solution for the trailing slash feature. I've created a draft PR to demonstrate it: endpoints4s/endpoints4s#742
Please let me know if this is the right direction (some tests will still fail because it involves changing the interpreters for the Urls algebra). The idea is that you can simply add a slash to a path like this:

endpoint(
  method = Get,
  url = path / segment[String]() / "",
  response = textResponse,
)

I like this because it's intuitive and idiomatic to endpoints' URL DSL. What do you think?

3 replies
I'd also like to explore ways to create endpoints that accept both a trailing slash and no trailing slash (an optional /). In REST endpoints it's not uncommon to accept both trailing and no trailing slash endpoints and let one redirect to the other. Do you think it's sensible to somehow build this into endpoints4s for ease of use?
Adriaan Groenenboom
@agboom
This message was deleted
Adriaan Groenenboom
@agboom
While adding to the EndpointsTestApi I noticed that some endpoints are only used in the server and some in the client test suites (e.g. deleteEndpoint only in server.EndpointsTestSuite and optionalEndpoint only in client.EndpointsTestSuite. I actually expected that all endpoints would be used in all tests, or might I be missing something?
2 replies
Adriaan Groenenboom
@agboom
Hi, I was looking at BuiltInErrors for a possible extension of the algebra and noticed that while the algebra is content type independent, the various interpreters always implement its methods with the application/json content type. My thought then was: wouldn't it be better to use jsonResponse from JsonEntities for this to prevent repeating this pattern? It occurred to me that the reason might be because you then had to mix in JsonEntities in BuiltInErrors and the latter is used in all the Endpoints interpreters it would enforce a possibly unwanted dependency on the user. Is that correct or is there some other reason?
3 replies
Adriaan Groenenboom
@agboom
Sorry for asking all these questions, but I have another one (please tell me if I need to stop :see_no_evil:). Did you at one time consider to add support for redirect endpoints? Currently, I need to explicitly add any redirect url to the server implementation. This feels somewhat awkward and of course the documentation or client support is left out. On the other hand, I can imagine that it's kind of a niche use case. When would you want to document redirects with OpenAPI, or support it in a client? In my case I have a server that is both a JSON API and an HTML staticfile server, of which the latter has redirects. For simplicity and clarity I'd like to define both with endpoints4s. I guess that's kind of a use case, be it a niche one. Another use case I can think of is API endpoints redirecting trailing slashes to no trailing slashes (e.g. /api/v1/users/ to /api/v1/users) or vice-versa. This is often done with APIs to make the endpoints more discoverable (not fail on a single slash). Both use cases can be implemented in pure server code of course, but I think it would be cool to use the clean interface of endpoints4s for this if possible. What do you think?
22 replies
Dominic Egger
@GrafBlutwurst
I noticed something recently when looking at our logs. Is it just me using it wrong or does handleClientErrors suffer from the fact that you don't know what route actually failed. e.g. in POST /foo/bar/ the body failed to decode, you won't know it was on POST /foo/bar
Julien Richard-Foy
@julienrf
@GrafBlutwurst Which server do you use?