Own-Programming-Language-Tu.../examples/server/server_spa_simple.own

20 lines
448 B
Scala
Raw Normal View History

2023-12-30 13:12:05 +02:00
use std, jdbc, server
// curl -X POST http://localhost:8084/notes/ -d "New note 2"
notes = []
createNote("This is your first note.")
def createNote(content) {
note = {"id": notes.length + 1, "content": content};
notes += note
return note
}
newServer({"externalDirs": ["notes_public"]})
.get("/notes", def(ctx) = ctx.json(notes))
.post("/notes", def(ctx) {
ctx.status(201)
ctx.json( createNote(ctx.body()) )
})
.start(8084)