Skip to content

Commit

Permalink
Add demo image
Browse files Browse the repository at this point in the history
  • Loading branch information
sake92 committed Jul 9, 2024
1 parent 2d0deb4 commit d246302
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .mill-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.11.5
0.11.8
2 changes: 1 addition & 1 deletion DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

37 changes: 37 additions & 0 deletions examples/scala-cli/demo.sc
Original file line number Diff line number Diff line change
@@ -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")
3 changes: 1 addition & 2 deletions sharaf/src/ba/sake/sharaf/ResponseWritable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit d246302

Please sign in to comment.