diff --git a/.mill-version b/.mill-version index b799a8c..772c67a 100644 --- a/.mill-version +++ b/.mill-version @@ -1 +1 @@ -0.11.5 \ No newline at end of file +0.11.8 \ No newline at end of file diff --git a/DEV.md b/DEV.md index cf5adea..3d79ecb 100644 --- a/DEV.md +++ b/DEV.md @@ -17,7 +17,7 @@ scala-cli compile examples\scala-cli git diff git commit -am "msg" -$VERSION="0.6.0" +$VERSION="0.7.0" git commit --allow-empty -m "Release $VERSION" git tag -a $VERSION -m "Release $VERSION" git push --atomic origin main $VERSION diff --git a/README.md b/README.md index 4811b06..46bf09c 100644 --- a/README.md +++ b/README.md @@ -4,3 +4,7 @@ Your new favorite, simple, intuitive, batteries-included web framework. WIP :construction: but very much usable. :construction_worker: + + +![](https://i.imgur.com/3a8FqWN.png) + diff --git a/examples/scala-cli/demo.sc b/examples/scala-cli/demo.sc new file mode 100644 index 0000000..99a4d0b --- /dev/null +++ b/examples/scala-cli/demo.sc @@ -0,0 +1,37 @@ +//> using scala "3.4.2" +//> using dep ba.sake::sharaf:0.6.0 + +import io.undertow.Undertow +import ba.sake.querson.QueryStringRW +import ba.sake.tupson.JsonRW +import ba.sake.validson.Validator +import ba.sake.sharaf.*, routing.* + +case class Car(model: String, quantity: Int) derives JsonRW + +case class CarQuery(model: Option[String]) derives QueryStringRW + +var carsDB = Seq[Car]() + +val routes = Routes: + case GET() -> Path("cars") => + val qp = Request.current.queryParamsValidated[CarQuery] + val filteredCars = qp.model match + case Some(b) => carsDB.filter(_.model == b) + case None => carsDB + Response.withBody(filteredCars) + + case POST() -> Path("cars") => + val newCar = Request.current.bodyJsonValidated[Car] + carsDB = carsDB.appended(newCar) + Response.withBody(newCar) + +Undertow.builder + .addHttpListener(8181, "localhost") + .setHandler( + SharafHandler(routes).withExceptionMapper(ExceptionMapper.json) + ) + .build + .start() + +println(s"Server started at http://localhost:8181") diff --git a/sharaf/src/ba/sake/sharaf/ResponseWritable.scala b/sharaf/src/ba/sake/sharaf/ResponseWritable.scala index 7b48167..f192fe6 100644 --- a/sharaf/src/ba/sake/sharaf/ResponseWritable.scala +++ b/sharaf/src/ba/sake/sharaf/ResponseWritable.scala @@ -27,8 +27,7 @@ object ResponseWritable { response.headerUpdates.updates.foreach { case HeaderUpdate.Set(name, values) => - exchange.getResponseHeaders.remove(name) - exchange.getResponseHeaders.addAll(name, values.asJava) + exchange.getResponseHeaders.putAll(name, values.asJava) case HeaderUpdate.Remove(name) => exchange.getResponseHeaders.remove(name) }