D
Deno

help

KV: What to return from here?

TMTimo Martinson7/20/2023
// 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)
}
})
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. šŸ˜¦
IioB7/20/2023
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"
TMTimo Martinson7/20/2023
ok with OAK what is this: Expected 0 type arguments, but got 1.deno-ts(2558) interface ICity
IioB7/20/2023
ah sorry, looks like that must have misremembered this functionality, disregard my prior comment what error are you getting?
TMTimo Martinson7/20/2023
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 } }
})
IioB7/20/2023
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?
TMTimo Martinson7/20/2023
oh yes thank you i forgot šŸ˜¦ silly me ssooooooo... GET works, POST doesn't ok now it works

Looking for more? Join the community!

Recommended 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[ignore] configuring botNothing to see here, ignore for now šŸ™‚Reuse Deno.serve for other TCP connectionsHello, As a newcommer to Deno, I wrote a client for NNTP protocol (https://github.com/sntran/deno_ndeno coverage crashI run ``` deno test -A --coverage=tmp/coverageData src ``` then ``` deno coverage --include=src/ tmpIs there a way to copy an element and place it somewhere else?Link: https://stackoverflow.com/questions/76704496/is-there-a-way-to-copy-an-element-and-place-it-sonot sure why this code is erroring```typescript for (const number of genNumbers()) { const result = await fetchPages(number); if (Why doesn't POST response from serveTls support streaming chunks from a ReadableStream?We can POST a ReadableStream to a serveTls server, however when we respond with a ReadableStream theWhen I use npm: node: specifiers how can I specify the version?We know in Deno we can do `import { Client, Pool } from "https://deno.land/x/pg@v0.6.1/mod.ts";` I wFakeTime seems to break async testsI am attempting to use FakeTime similarly to in the Faking time example of https://deno.land/manual@How to serve HTTPS with the Deno.serve() APII used to start a dev server with TLS like so ```const server = Deno.listenTls({ port: 7000, trCustom console.log formatting for a class/objectIs there a way to change the way an object/class is printed in the console? For example, instead of