Skip to content

Instantly share code, notes, and snippets.

@ishiduca
Last active July 15, 2022 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ishiduca/9d45e4e9345c0f52f6392e72dacce40e to your computer and use it in GitHub Desktop.
Save ishiduca/9d45e4e9345c0f52f6392e72dacce40e to your computer and use it in GitHub Desktop.
http レスポンスの処理とロジックの処理を分離させたい。
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)}`
})
{
"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