What's a good library for mocking server (to test http clients)?

I am searching for a library which can spawn up http server and return some response that can be fed into it. I came across wiremock and javalin.

I wanted to know if there is a library which was built in Scala and can be used using Scala idioms (would be awesome if it could understand circe json)?

Not a library, but I usually use SoapUI for that.

1 Like

I’ve been using WireMock so far. It works, but it’s pretty javaesque, and in particularly the split API for expressing mappings and verifications is somewhat cumbersome. I’d be happy to hear about alternatives, not necessarily but ideally with a native Scala API, as well…

A possible option to consider: I actually build the server directly into my unit tests using Play itself when I need this sort of thing for my Play applications. You can use play.core.server.Router.withRouter() to construct a mock server in-process, and then feed the resulting port into your application, if the URL it connects to is configurable.

That’s only really the way to go if you are building a Play app, but I’ve found it very convenient if so, being able to have the code, the test, and the test server all in the same codebase.

More generally, I might try using Cask – a nice straightforward HTTP server from Li Haoyi – for this sort of thing. It’s about as lightweight a Scala server as you can get.

1 Like