Timo Martinson
Timo Martinsonā€¢11mo ago

KV: What to return from here?

// Create City
router.post('/cities', async (context) => {
const data = await context.request.body().value
if (data.slug && data.name) {
await kv.set(['cities', data.slug], {
slug: data.slug,
name: data.name,
description: data.description
} satisfies ICity)
}
})
// Create City
router.post('/cities', async (context) => {
const data = await context.request.body().value
if (data.slug && data.name) {
await kv.set(['cities', data.slug], {
slug: data.slug,
name: data.name,
description: data.description
} satisfies ICity)
}
})
7 Replies
Timo Martinson
Timo Martinsonā€¢11mo ago
let me add this: request: { url: "http://localhost:4040/cities", method: "POST", hasBody: true } response: { status: 404, type: undefined, hasBody: false, writable: true } This is the error. Internal Server Error. šŸ˜¦
ioB
ioBā€¢11mo ago
what framework are you using also, why not use
await kv.set<ICity>(['cities', data.slug], {
slug: data.slug,
name: data.name,
description: data.description
})
await kv.set<ICity>(['cities', data.slug], {
slug: data.slug,
name: data.name,
description: data.description
})
instead of trying to hack it in with "satisfies"
Timo Martinson
Timo Martinsonā€¢11mo ago
ok with OAK what is this: Expected 0 type arguments, but got 1.deno-ts(2558) interface ICity
ioB
ioBā€¢11mo ago
ah sorry, looks like that must have misremembered this functionality, disregard my prior comment what error are you getting?
Timo Martinson
Timo Martinsonā€¢11mo ago
Internal Server Error šŸ˜¦ and when i make a get-request: 404 not found
// List Cities
router.get('/cities', async () => {
const list = kv.list<ICity[]>({ prefix: ['cities'] })
const cities = []
for await (const city of list) cities.push(city)
return { data: { cities } }
})
// List Cities
router.get('/cities', async () => {
const list = kv.list<ICity[]>({ prefix: ['cities'] })
const cities = []
for await (const city of list) cities.push(city)
return { data: { cities } }
})
ioB
ioBā€¢11mo ago
looking at the docs, i have no idea where you're getting a return statement from don't you have to set ctx.response.body?
Timo Martinson
Timo Martinsonā€¢11mo ago
oh yes thank you i forgot šŸ˜¦ silly me ssooooooo... GET works, POST doesn't ok now it works
More Posts
Log Deno.command process outputi need to execute a command wich will keep running until stopped and log the output. i found this buUncaught TypeError: Cannot set properties of null (setting 'innerHTML')Code: var bcb = new WebSocket('wss://stream.binance.com:9443/ws/bnbusdt@trade'); bcb.onmessage = (It's hard to read that the font used in the official Deno website.On the official Deno website (deno.land), I think it difficult to distinguish between upper and lowePetition to free the module x/type from deno.landHere is the module url: https://deno.land/x/type It says it would be deleted after 30 days but has Docs on understanding how Fresh works under the hood.I want to start becoming a contributor for Fresh, I have been looking at PRs and reading documents wNode MongoDB Driver on Deno dropping connection and crashing processHeya folks. I am encountering the most recent error described in this thread https://github.com/denoHow to solve "cannot be invoked without 'new'" thrown from an NPM module ?Hello, An NPM module (which I don't own) uses `call` on something, which throws a `cannot be invokeCoverage with subprocessOne of my tests involves spawning a subprocess. Is there any way to get this subprocess to participaHow to exclude folder from deno lintI use WebStorm. How to exclude specific folder from deno lint? Is it possible in WebStorm? It is posTypeScript compiler type declarationsI'm using `import ts from "npm:typescript"` to work with the TypeScript compiler, but how do I get t