REST API Documentation example taken from https://github.com/bbc/REST-API-example
The entire application is contained within the index.ts file.
All routes are contained on one file due to Vercel requirements when using express js. If it is possible, a solution could not be found on their documentation.
vercel.json is a config file to allow Vercel to host an express app as a serverless function.
npm install
npm start
The REST API to the example app is described below.
The user is hardcoded and so all requests return data for a specific user, this can be extended in the future to allow multiple users.
DISCLAIMER: FILES UPLOADED ABOVE 5MB WILL FAIL
GET /api/brandguides
[
{
"name": "Audi",
"imageUrl": "https://www.teahub.io/photos/full/6-66951_wiki-free-audi-iphone-image-pic-wpc0010850-data.jpg",
"subdomain": "audi"
},
{
"subdomain": "johnniewalker",
"imageUrl": "https://mir-s3-cdn-cf.behance.net/project_modules/disp/0cd84925304975.56343b9c7bf1c.jpg",
"name": "Johnnie Walker"
},
]
POST api/brandguides/:bgsName
{
"name": "Audi",
"imageUrl": "https://www.teahub.io/photos/full/6-66951_wiki-free-audi-iphone-image-pic-wpc0010850-data.jpg",
"subdomain": "audi"
},
You can choose to omit the imageUrl field
If succeeded it returns a 200 OK, Otherwise 403 Forbidden
PUT /api/brandguides/:bgsName/upload
Accepts formdata, name should be "file" and value field should be the file you want to upload.
If succeeded it returns a 200 OK, it will fail and give a vercel error of "FUNCTION PAYLOAD TOO LARGE" if the file is over 5MB
PUT api/brandguides/:bgsName?field=:fieldName&value=:value
:fieldName (I.E. subdomain, imageUrl, name, isLive) and :value (the string value you want to update/add to)
If succeeded it returns a 200 OK
PUT api/brandguides/:bgsName/:pageName?field=:fieldName&value=:value
:fieldName (I.E. containsDefaultFont, isCoreComponent, name) and :value (the string value you want to update/add to)
If succeeded it returns a 200 OK
POST /api/brandguides/:bgsName/:pageName/upload/image
Accepts formdata, name should be "file" and value field should be the file you want to upload.
If succeeded it returns a 200 OK, it will fail and give a vercel error of "FUNCTION PAYLOAD TOO LARGE" if the file is over 5MB
POST /api/brandguides/:bgsName/:pageName/upload/blob
Accepts formdata, name should be "file" and value field should be the file you want to upload.
If succeeded it returns a 200 OK, it will fail and give a vercel error of "FUNCTION PAYLOAD TOO LARGE" if the file is over 5MB
POST /api/brandguides/:bgsName/:pageName
If succeeded it returns a 200 OK
It initializes a page with an object body like below
{
"name": "Typography",
"containsDefaultFont": false,
"isCoreComponent": false,
Assets: [],
}GET /api/brandguides/:bgsName/:pageName
{
"Assets": [
{
"content": {
"value": "'Oswald', sans-serif",
"variant": "subtitle"
},
"name": "text7",
"type": "text"
},
{
"content": {
"value": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, qui",
"variant": "paragraph"
},
"name": "text8",
"type": "text"
}
],
"containsDefaultFont": false,
"name": "Typography",
"isCoreComponent": false
}GET /api/brandguides/:bgsName
{
"imageUrl": "https://mir-s3-cdn-cf.behance.net/project_modules/disp/0cd84925304975.56343b9c7bf1c.jpg",
"subdomain": "johnniewalker",
"name": "Johnnie Walker",
"pages": [
{
"containsDefaultFont": false,
"name": "About",
"Assets": [
{
"type": "text",
"name": "text1",
"content": {
"value": "Johnnie Walker wh...",
"variant": "paragraph"
}
},
],
"isCoreComponent": false
},
{
"name": "Colors",
"Assets": [
{
"type": "color",
"name": "Primary Colors",
"content": {
"colors": [
{
"name": "SuperWhite",
"blue": 255,
"red": 255,
"green": 255
},
{
"name": "Light Grayish Yellow",
"green": 246,GET /api/brandguides/:bgsName?subdomain=true&nodata=true
if succeeded it returns a 200 OK, Otherwise a 404 Not Found
GET /api/brandguides/:bgsName?subdomain=true
{
"imageUrl": "https://mir-s3-cdn-cf.behance.net/project_modules/disp/0cd84925304975.56343b9c7bf1c.jpg",
"subdomain": "johnniewalker",
"name": "Johnnie Walker",
"pages": [
{
"containsDefaultFont": false,
"name": "About",
"Assets": [
{
"type": "text",
"name": "text1",
"content": {
"value": "Johnnie Walker wh...",
"variant": "paragraph"
}
},
],
"isCoreComponent": false
},
{
"name": "Colors",
"Assets": [
{
"type": "color",
"name": "Primary Colors",
"content": {
"colors": [
{
"name": "SuperWhite",
"blue": 255,
"red": 255,
"green": 255
},
{
"name": "Light Grayish Yellow",
"green": 246,GET /api/brandguides/:bgsName/fonts
@font-face {
font-family: 'Gilroy ExtraBold';
src: url(https://firebasestorage.googleapis.com/v0/b/markr-7d6ab.appspot.com/o/Gilroy-ExtraBold.otf?alt=media) format("opentype");
}
@font-face {
font-family: 'Gilroy Light';
src: url(https://firebasestorage.googleapis.com/v0/b/markr-7d6ab.appspot.com/o/Gilroy-Light.otf?alt=media) format("opentype");
}
PUT /api/brandguides/:bgsName/:pageName/:assetIndex
{
"content": {
"variant": "subtitle",
"value": "The quick brown fox jumps over the lazy dog"
},
"name": "text1",
"type": "text"
}All asset types need a content: any, name: String, and type: String
If succeeded it returns a 200 OK, Otherwise a 403 Forbidden
NOT IMPLEMENTED
NOT IMPLEMENTED
NOT IMPLEMENTED