mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 08:44:20 +03:00
20 lines
448 B
Scala
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) |