Own-Programming-Language-Tu.../examples/server/server_spa_simple.own
2024-01-12 20:52:30 +01:00

20 lines
448 B
Scala

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)