Created
August 19, 2023 08:03
-
-
Save vicradon/23f036ffed72f2d1d24bdbe35794c76a to your computer and use it in GitHub Desktop.
Create a new document in a cosmos db container using an extra outputs binding
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
import { | |
app, | |
HttpRequest, | |
HttpResponseInit, | |
InvocationContext, | |
output, | |
} from "@azure/functions"; | |
const cosmosDBOutput = output.cosmosDB({ | |
connection: "CosmosDBConnection", | |
databaseName: "coin-flip-db", | |
containerName: "coin-flip-sessions", | |
}); | |
export async function CreateDoc( | |
request: HttpRequest, | |
context: InvocationContext | |
): Promise<HttpResponseInit> { | |
context.log(`Http function processed request for url "${request.url}"`); | |
const name = request.query.get("name") || (await request.text()) || "world"; | |
context.extraOutputs.set(cosmosDBOutput, [{ name }]); | |
return { | |
jsonBody: { | |
hi: "there", | |
}, | |
}; | |
} | |
app.http("CreateDoc", { | |
methods: ["GET", "POST"], | |
authLevel: "anonymous", | |
handler: CreateDoc, | |
extraOutputs: [cosmosDBOutput], | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment