Last active
July 15, 2022 00:39
-
-
Save ishiduca/9d45e4e9345c0f52f6392e72dacce40e to your computer and use it in GitHub Desktop.
http レスポンスの処理とロジックの処理を分離させたい。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
get('/tanka/:id', 'html', async (datas) => { | |
var { param, query } = datas | |
var { tanka, author, created } = await api.getTanka(param.id) | |
return html({ body: yo`<main><h1>${tanka}</h1><p class="author">${author.name}</p></main>` }) | |
}) | |
get('/author/:authorId', [ 200, 'json' ], async (datas) => { | |
var { param, query } = datas | |
var author = await api.getAuthor(param.authorId) | |
var tankas = await api.getTankaList(author.id) | |
return tankas | |
}) | |
post('/tanka/create', 'json', auth(body(async (datas) => { | |
var { param, query, _, author } = datas | |
var tanka = JSON.parse(_) | |
var res = await api.createTanka({ ...tanka, author }) | |
return res | |
}))) | |
onError([ 500, { 'content-type': 'text/plain' } ], (error) => { | |
return `${String(error)}\n${String(error.stack)}` | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"type": "array", | |
"items": [ | |
{ "type": "integer" }, | |
{ "$ref": "#/definitions/headers" }, | |
{ "type": "string" } | |
], | |
"minItems": 3, | |
"definitions": { | |
"headers": { | |
"type": "object", | |
"required": [ "content-type" ], | |
"properties": { | |
"content-type": { | |
"type": "string" | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment