Skip to content

Commit 5cedbda

Browse files
committed
Rewrite README: update versions, trim boilerplate, add badges
1 parent c85d2d4 commit 5cedbda

1 file changed

Lines changed: 45 additions & 113 deletions

File tree

README.md

Lines changed: 45 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,50 @@
11
# http4s-stir
22

3-
Welcome to http4s-stir, a library designed to bridge the gap between Pekko HTTP (Akka HTTP) and http4s. This README provides an overview of the library, its usage, project status, and more.
3+
[![Maven Central](https://img.shields.io/maven-central/v/pl.iterators/http4s-stir_3)](https://central.sonatype.com/artifact/pl.iterators/http4s-stir_3)
4+
[![CI](https://github.com/theiterators/http4s-stir/actions/workflows/ci.yml/badge.svg)](https://github.com/theiterators/http4s-stir/actions/workflows/ci.yml)
45

5-
http4s-stir offers [Pekko HTTP](https://github.com/apache/incubator-pekko-http)-style (Akka HTTP-style) DSL directives for [http4s](https://github.com/http4s/http4s) using cats-effect's IO as an effect system. About 85% of all directives have been ported. Some were omitted due to a lack of support in http4s, while others were modified to fit http4s' distinct architecture. For specifics, refer to the [Missing](#missing) section below.
6+
[Pekko HTTP](https://github.com/apache/incubator-pekko-http) (Akka HTTP) style DSL directives for [http4s](https://github.com/http4s/http4s) with cats-effect IO. About 85% of all directives have been ported. Includes a test kit similar to Pekko's.
67

7-
Additionally, there's a compatibility layer, [`Http4sDirectives`](https://github.com/theiterators/http4s-stir/blob/master/core/src/main/scala/pl/iterators/stir/server/directives/Http4sDirectives.scala), for http4s-dsl routes.
8+
Cross-compiled for JVM, Scala.js, and Scala Native. Supports Scala 2.13 and Scala 3.
89

9-
http4s-stir also furnishes a test kit akin to Pekko's (Akka's).
10-
11-
## How to use it
12-
13-
### Installation
14-
15-
In SBT:
10+
## Installation
1611

1712
```scala
18-
libraryDependencies += "pl.iterators" %% "http4s-stir" % "0.4.0"
19-
libraryDependencies += "pl.iterators" %% "http4s-stir-testkit" % "0.4.0" % Test // if you need this
13+
// build.sbt
14+
libraryDependencies += "pl.iterators" %% "http4s-stir" % "0.4.1"
15+
libraryDependencies += "pl.iterators" %% "http4s-stir-testkit" % "0.4.1" % Test
2016
```
2117

22-
For `scala-cli` see [this example](#example).
23-
24-
### Example
18+
## Quick example
2519

26-
Here's an example in Scala 3 that you can run using scala-cli:
20+
A complete example you can run with `scala-cli run .`:
2721

2822
```scala 3
2923
// Main.scala
30-
//> using dep org.typelevel::cats-effect::3.5.4
31-
//> using dep org.http4s::http4s-dsl::0.23.33
24+
//> using dep pl.iterators::http4s-stir::0.4.1
3225
//> using dep org.http4s::http4s-ember-server::0.23.33
3326
//> using dep org.http4s::http4s-circe::0.23.33
34-
//> using dep io.circe::circe-core::0.14.15
3527
//> using dep io.circe::circe-generic::0.14.15
36-
//> using dep pl.iterators::http4s-stir::0.4.0
28+
//> using dep org.typelevel::cats-effect::3.7.0
3729

3830
import org.http4s.Status
3931
import org.http4s.ember.server.EmberServerBuilder
4032
import org.http4s.circe.CirceEntityEncoder.*
4133
import org.http4s.circe.CirceEntityDecoder.*
4234
import io.circe.*
4335
import io.circe.generic.semiauto.*
44-
import cats.effect.IO
36+
import cats.effect.{IO, IOApp}
4537
import pl.iterators.stir.server.*
4638
import pl.iterators.stir.server.Directives.*
47-
import cats.effect.IOApp
4839

49-
// example rewritten from https://pekko.apache.org/docs/pekko-http/current/introduction.html#using-apache-pekko-http
5040
var orders: List[Item] = Nil
5141

52-
// domain model
5342
final case class Item(name: String, id: Long)
5443
final case class Order(items: List[Item])
5544

56-
// formats for unmarshalling and marshalling
5745
given Codec[Item] = deriveCodec[Item]
5846
given Codec[Order] = deriveCodec[Order]
5947

60-
// (fake) async database query api
6148
def fetchItem(itemId: Long): IO[Option[Item]] = IO.delay {
6249
orders.find(o => o.id == itemId)
6350
}
@@ -70,9 +57,7 @@ val route: Route =
7057
concat(
7158
get {
7259
pathPrefix("item" / LongNumber) { id =>
73-
// there might be no item for a given id
7460
val maybeItem: IO[Option[Item]] = fetchItem(id)
75-
7661
onSuccess(maybeItem) {
7762
case Some(item) => complete(item)
7863
case None => complete(Status.NotFound)
@@ -83,9 +68,8 @@ val route: Route =
8368
path("create-order") {
8469
entity(as[Order]) { order =>
8570
val saved: IO[List[Item]] = saveOrder(order)
86-
onSuccess(saved) {
87-
_ => // we are not interested in the result value `Done` but only in the fact that it was successful
88-
complete("order created")
71+
onSuccess(saved) { _ =>
72+
complete("order created")
8973
}
9074
}
9175
}
@@ -94,23 +78,22 @@ val route: Route =
9478

9579
object Main extends IOApp.Simple {
9680
val run = EmberServerBuilder
97-
.default[IO]
98-
.withHttpApp(route.toHttpRoutes.orNotFound)
99-
.build
100-
.use(_ => IO.never)
81+
.default[IO]
82+
.withHttpApp(route.toHttpRoutes.orNotFound)
83+
.build
84+
.use(_ => IO.never)
10185
}
102-
10386
```
10487

105-
To run this service you can use `scala-cli run .`.
88+
### Testing
10689

107-
Or maybe if you want, you can compile it to JS file: `scala-cli --power package --js --js-module-kind commonjs Main.scala`.
90+
http4s-stir includes a test kit with familiar `~>` routing test syntax:
10891

10992
```scala 3
11093
// Main.test.scala
111-
//> using test.dep org.specs2::specs2-core:5.5.8
112-
//> using test.dep pl.iterators::http4s-stir-testkit:0.4.0
94+
//> using test.dep pl.iterators::http4s-stir-testkit:0.4.1
11395
//> using test.dep org.http4s::http4s-circe:0.23.33
96+
//> using test.dep org.specs2::specs2-core:5.5.8
11497

11598
import org.http4s.Status
11699
import org.http4s.circe.CirceEntityEncoder.*
@@ -128,7 +111,6 @@ class MainRoutesSpec extends Specification with Specs2RouteTest {
128111
"create order" in {
129112
Post("/create-order", Order(List(Item("foo", 42)))) ~> route ~> check {
130113
responseAs[String] must contain("order created")
131-
orders.head must beEqualTo(Item("foo", 42))
132114
}
133115
}
134116
"retrieve an item if present" in {
@@ -145,95 +127,45 @@ class MainRoutesSpec extends Specification with Specs2RouteTest {
145127
}
146128
}
147129
}
148-
149130
```
150131

151-
To run the tests you can use `scala-cli test .`.
152-
153-
For a more comprehensive example showcasing additional directives see [examples](https://github.com/theiterators/http4s-stir/blob/master/examples/src/main/scala/Service.scala). You can run it with `~examples/reStart`.
154-
155-
## Why this library?
156-
157-
Here's why I embarked on this project:
158-
159-
- After the license change for Akka, many contemplated transitioning to http4s and the Typelevel stack. I wanted to simplify this migration.
160-
- While I'm a fan of cats-effect, I find the http4s DSL verbose and clunky. Marrying Pekko HTTP (Akka HTTP) with cats-effect seemed inelegant, so http4s-stir could be the remedy.
161-
- I was curious about the internals of both Pekko HTTP and http4s and wanted to determine the feasibility of this project.
162-
- And, of course, a bit of playful provocation - [see the next section](#whats-with-the-name).
132+
Run with `scala-cli test .`.
163133

164-
## What's with the name?
165-
166-
> **stir something up** (pv)
167-
>
168-
> *to cause an unpleasant emotion or problem to begin or grow*
134+
For a more comprehensive example showcasing additional directives, see [examples/Service.scala](https://github.com/theiterators/http4s-stir/blob/master/examples/src/main/scala/Service.scala). Run it locally with `sbt ~examples/reStart`.
169135

170-
There are folks who adore http4s but detest Pekko's (or Akka's) DSL. Conversely, there are those who champion Pekko's (or Akka's) but disdain http4s DSL. I aimed to ruffle feathers from both camps with a hybrid library.
136+
## http4s-dsl compatibility
171137

172-
## Project status
138+
There's a compatibility layer, [`Http4sDirectives`](https://github.com/theiterators/http4s-stir/blob/master/core/src/main/scala/pl/iterators/stir/server/directives/Http4sDirectives.scala), that lets you embed existing http4s-dsl routes within stir routes.
173139

174-
This library is in preview, intended to collect initial feedback. Yet, I am dedicated to its ongoing maintenance and enhancement, especially as it undergoes real-world testing. Contributions are very welcome.
140+
## What's missing
175141

176-
## Missing
142+
Some Pekko HTTP directives are absent or modified:
177143

178-
Certain directives from the original are either absent or have been modified:
179-
180-
* Assuming and converting to/from strict entity
181-
* `CacheConditionDirectives`
182-
* `CodingDirectives`
183-
* directory listing in `FileAndResourceDirectives`
184-
* `RangeDirectives`
144+
* `CacheConditionDirectives`, `CodingDirectives`, `RangeDirectives`
145+
* Directory listing in `FileAndResourceDirectives`
185146
* `checkSameOrigin` in `HeaderDirectives`
186-
* handling of multipart forms in `FormFieldDirectives` (but I don't like it anyway)
187-
* Some of how akka configures things
188-
* `withSizeLimit`
189-
* `withoutSizeLimit`
190-
* `requestEntityEmpty`
191-
* `requestEntityPresent`
192-
* `rejectEmptyResponse`
193-
* `extractRequestTimeout`
194-
* `withRequestTimeoutResponse`
195-
* AttributeDirectives
196-
* FramedEntityStreamingDirectives
197-
* WebSocketDirectives in large part
198-
* Testkit needed significant changes
199-
* Not async anymore
200-
* Chunks not supported
201-
* Request building incomplete (missing some minor header methods)
202-
* All websocket thingies
203-
* Some logic of transparent headers and default host info
204-
205-
## Support
206-
207-
### Encountering a Problem?
147+
* Multipart form handling in `FormFieldDirectives`
148+
* `AttributeDirectives`, `FramedEntityStreamingDirectives`
149+
* Most of `WebSocketDirectives`
150+
* Strict entity conversion, `withSizeLimit`, `withoutSizeLimit`, `requestEntityEmpty`, `requestEntityPresent`, `rejectEmptyResponse`
151+
* Testkit differences: synchronous execution, no chunk support, limited request building, no WebSocket testing
208152

209-
If you run into any issues, unexpected behavior, or errors, we encourage you to report them. Your feedback is invaluable and helps us improve.
210-
211-
### Have a Feature Request?
212-
213-
If there's a feature you'd like to see, or if you have an idea that would make this project even better, we'd love to hear about it!
214-
215-
### How to Report an Issue or Feature Request
216-
217-
Please create a new issue in our [http4-stir](https://github.com/theiterators/http4s-stir/issues). Ensure you provide as much detail as possible:
153+
## What's with the name?
218154

219-
1. **For issues:**
220-
- Describe the issue you're facing.
221-
- Steps to reproduce.
222-
- Expected behavior.
223-
- Actual behavior.
155+
> **stir something up** (pv)
156+
>
157+
> *to cause an unpleasant emotion or problem to begin or grow*
224158
225-
2. **For feature requests:**
226-
- Describe the feature and why you believe it would be useful.
227-
- Any reference or example from other projects/tools, if applicable.
159+
Some love http4s DSL but dislike Pekko's. Others feel the opposite. This library stirs things up by combining both.
228160

229-
By providing detailed information, you'll help us address your concerns more efficiently.
161+
## Contributing
230162

231-
Thank you for your contributions and for helping make this project better for everyone!
163+
Issues and PRs welcome at [github.com/theiterators/http4s-stir](https://github.com/theiterators/http4s-stir/issues).
232164

233165
## License
234166

235-
http4s-stir is under the Apache License, Version 2.0 ("the License"). You must comply with this License to use this software. A [full license text](https://github.com/theiterators/http4s-stir/blob/master/LICENSE) is available in the repository.
167+
Apache License 2.0. See [LICENSE](https://github.com/theiterators/http4s-stir/blob/master/LICENSE).
236168

237169
## Acknowledgements
238170

239-
http4s-stir incorporates significant portions of code adapted from [Pekko HTTP](https://github.com/apache/incubator-pekko-http), a fork of [Akka HTTP](https://github.com/akka/akka-http).
171+
http4s-stir incorporates code adapted from [Pekko HTTP](https://github.com/apache/incubator-pekko-http), a fork of [Akka HTTP](https://github.com/akka/akka-http).

0 commit comments

Comments
 (0)