MCPcopy Create free account
hub / github.com/CodeWithHarry/Sigma-Web-Dev-Course / POST

Function POST

Video 137/linktree-clone/app/api/add/route.js:4–21  ·  view source on GitHub ↗
(request)

Source from the content-addressed store, hash-verified

2
3
4export async function POST(request) {
5 const body = await request.json()
6
7 const client = await clientPromise;
8 const db = client.db("bittree")
9 const collection = db.collection("links")
10
11 // If the handle is already claimed, you cannot create the bittree
12 const doc = await collection.findOne({handle: body.handle})
13
14 if (doc){
15 return Response.json({ success: false, error: true, message: 'This Bittree already exists!', result: null })
16 }
17
18 const result = await collection.insertOne(body)
19
20 return Response.json({ success: true, error: false, message: 'Your Bittree has been generated!', result: result, })
21 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected