-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathroute.ts
More file actions
50 lines (46 loc) · 1.34 KB
/
route.ts
File metadata and controls
50 lines (46 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { NextRequest } from 'next/server';
import * as credentials from '@/lib/credentials';
/**
* POST /api/credentials
* Adds a new credential to the database.
*
* Request:
* - `Content-type: application/json` header is required (otherwise, the JSON
* body parser for Next.js API routes won't activate).
*
* - Body is of the format:
* {
* vp: signed verifiable presentation goes here
* }
*
* Response (content-type: application/json):
* {
* "url": {
* // human-readable HTML view of the credential
* "view": "/credentials/{publicCredentialId}",
*
* // raw JSON GET (used by the html view)
* "get": "/api/credentials/{publicCredentialId}",
*
* // used for DELETE/unshare API
* "unshare": "/api/credentials/{publicCredentialId}"
* }
* }
*
* (Note the /api/ prefix in the get and unshare URLs, above).
*/
export async function POST(request: NextRequest) {
try {
const credential = await request.json();
const result = await credentials.post(credential);
const headers = {'Location': result.url.view};
return Response.json({ status: 'Credential added', ...result }, {status:201, headers})
} catch (error) {
console.error(error);
return Response.json({
status: 'Invalid request',
// @ts-ignore
error: error.message
}, {status: 400})
}
}