Skip to content

API reference

Armandas edited this page Oct 15, 2023 · 14 revisions

Museum app API reference

Here you can reference how to use a specific API route from museum app.

Museum

GET /museums Get a list of museums

GET museums

Returns a list of museums and if there is a next page.

Query parameters

name type data type description
page optional number Page number (page ∈ ℕ)
pageSize optional number Amount of museums per page (pageSize ∈ ℕ ∩ [5,30])

Responses

HTTP Code Content-Type Response
200 application/json
{
    "museums": [
        {
            "id": 8,
            "name": "Uffizi Gallery",
            "description": "Uffizi Gallery",
            "imageUrl": null
        },
        {
            "id": 9,
            "name": "The Metropolitan Museum of Art",
            "description": "The Metropolitan Museum of Art",
            "imageUrl": null
        },
        {
            "id": 14,
            "name": "ggasg",
            "description": "gasgs",
            "imageUrl": null
        },
        {
            "id": 15,
            "name": "ggasg",
            "description": "gasgs",
            "imageUrl": null
        },
        {
            "id": 16,
            "name": "ggasg",
            "description": "gasgs",
            "imageUrl": null
        }
    ],
    "hasNext": true
}
422 application/json
{
    "errors": [
        {
            "field": "page",
            "message": "Expected number, received nan"
        }
    ]
}

Example cURL

curl --location 'http://localhost:4000/api/v1/museums?page=2&pageSize=5'
GET /museums/:museumId Get a single museum

GET a museum

Parameters

name type data type description
museumId required number The id of the museum

Responses

HTTP Code Content-Type Response
200 application/json
{
    "museum": {
        "id": 7,
        "name": "Rijksmuseum",
        "description": "Rijksmuseum",
        "imageUrl": null
    }
}
404 application/json
{
    "errors": [
        "Museum not found"
    ]
}
422 application/json
{
    "errors": [
        {
            "field": "museumId",
            "message": "Expected number, received nan"
        }
    ]
}

Example cURL

curl --location 'http://localhost:4000/api/v1/museums/1'
POST /museums Create a new museum (ADMIN)
USER MUST BE AN ADMIN

POST create a new museum

Headers

name type data type description
Authorization required string Token must be a bearer token

JSON body parameters

name type data type description
name required string Title of the museum
description required string Description of the museum

Responses

HTTP Code Content-Type Response
201 application/json
{
    "museum": {
        "id": 20,
        "name": "MusMus4",
        "description": "Museum description very large building lots and lots of items and categories",
        "imageUrl": null
    }
}
401 application/json
{
    "errors": [
        "Invalid access token"
    ]
}
422 application/json
{
    "errors": [
        {
            "field": "name",
            "message": "Required"
        }
    ]
}

Example cURL

 curl --location 'http://localhost:4000/api/v1/museums' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJhbGciOiJIbzI1NiJ9.ey...gS_kLNb1Cdaujo' \
--data '{
    "name": "MusMus4",
    "description": "Museum description very large building lots and lots of items and categories"
}'
PUT /museums/:museumId Update museum data (ADMIN)
USER MUST BE AN ADMIN

PUT update museum data

Updates museum values in database and returns an object with the updated values.

Headers

name type data type description
Authorization required string Token must be a bearer token

Parameters

name type data type description
museumId required number The id of the museum

JSON body parameters

name type data type description
name required string Title of the museum
description required string Description of the museum

Responses

HTTP Code Content-Type Response
200 application/json
{
    "museum": {
        "id": 6,
        "name": "Museum22",
        "description": "Some changed lorem ipsum whatever it means in latin and thats it",
        "imageUrl": null
    }
}
401 application/json
{
    "errors": [
        "Invalid access token"
    ]
}
404 application/json
{
    "errors": [
        "Museum not found!"
    ]
}
422 application/json
{
    "errors": [
        {
            "field": "name",
            "message": "Expected string, received null"
        }
    ]
}

Example cURL

curl --location --request PUT 'http://localhost:4000/api/v1/museums/64' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJhbGciOiJIbzI1NiJ9.ey...gS_kLNb1Cdaujo' \
--data '{
    "name": "Museum22",
    "description": "Some changed lorem ipsum whatever it means in latin and thats it"
}'
DELETE /museums/:museumId Delete a museum (ADMIN)
USER MUST BE AN ADMIN

DELETE a museum

Deletes a museum and all categories and items within those categories.

Headers

name type data type description
Authorization required string Token must be a bearer token

Parameters

name type data type description
museumId required number The id of the museum

Responses

HTTP Code Content-Type Response
204
401 application/json
{
    "errors": [
        "Invalid access token"
    ]
}
404 application/json
{
    "errors": [
        "Museum not found!"
    ]
}
422 application/json
{
    "errors": [
        {
            "field": "museumId",
            "message": "Expected number, received nan"
        }
    ]
}

Example cURL

curl --location --request DELETE 'http://localhost:4000/api/v1/museums/18' \
--header 'Authorization: Bearer eyJhbGciOiJIbzI1NiJ9.ey...gS_kLNb1Cdaujo'

Categories

GET /museums/:museumId/categories Get a list of museum categories

GET museum categories

Query parameters

name type data type description
page optional number Page number (page ∈ ℕ)
pageSize optional number Amount of categories per page (pageSize ∈ ℕ ∩ [5,30])

Responses

HTTP Code Content-Type Response
200 application/json
{
    "categories": [
        {
            "id": 15,
            "createdAt": "2023-09-28T18:13:36.121Z",
            "name": "fffg",
            "description": "ffgsg",
            "museumId": 1,
            "imageUrl": null
        },
        {
            "id": 16,
            "createdAt": "2023-09-28T18:13:37.374Z",
            "name": "fffg",
            "description": "ffgsg",
            "museumId": 1,
            "imageUrl": null
        },
        {
            "id": 17,
            "createdAt": "2023-09-28T18:13:38.465Z",
            "name": "fffg",
            "description": "ffgsg",
            "museumId": 1,
            "imageUrl": null
        },
        {
            "id": 18,
            "createdAt": "2023-09-28T18:13:39.564Z",
            "name": "fffg",
            "description": "ffgsg",
            "museumId": 1,
            "imageUrl": null
        },
        {
            "id": 20,
            "createdAt": "2023-09-28T18:13:41.692Z",
            "name": "fffg",
            "description": "ffgsg",
            "museumId": 1,
            "imageUrl": null
        }
    ],
    "hasNext": true
}
422 application/json
{
    "errors": [
        {
            "field": "page",
            "message": "Expected number, received nan"
        }
    ]
}

Example cURL

curl --location 'http://localhost:4000/api/v1/museums/1/categories?page=1&pageSize=10'
GET /museums/:museumId/categories/:categoryId Get a single category

GET a category

Parameters

name type data type description
museumId required number The id of the museum
categoryId required number The id of the category

Responses

HTTP Code Content-Type Response
200 application/json
{
    "category": {
        "id": 30,
        "createdAt": "2023-10-15T19:15:15.003Z",
        "name": "Paintings",
        "description": "Until recently, the prevailing view assumed lorem ipsum was born as a nonsense text.",
        "museumId": 7,
        "imageUrl": null,
        "museum": {
            "name": "Rijksmuseum"
        }
    },
    "canEdit": false
}
404 application/json
{
    "errors": [
        "Category not found!"
    ]
}
422 application/json
{
    "errors": [
        {
            "field": "categoryId",
            "message": "Expected number, received nan"
        }
    ]
}

Example cURL

curl --location --request GET 'http://localhost:4000/api/v1/museums/7/categories/30'
POST /museums/:museumId/categories Create a new category(ADMIN)
USER MUST BE AN ADMIN

POST create a new category

Headers

name type data type description
Authorization required string Token must be a bearer token

Parameters

name type data type description
museumId required number The id of the museum

JSON body parameters

name type data type description
name required string Title of the museum
description required string Description of the museum

Responses

HTTP Code Content-Type Response
201 application/json
{
    "category": {
        "id": 31,
        "createdAt": "2023-10-15T19:27:02.734Z",
        "name": "Description about the sculptures category",
        "description": "Sculptures",
        "museumId": 1,
        "imageUrl": null
    }
}
401 application/json
{
    "errors": [
        "Invalid access token"
    ]
}
422 application/json
{
    "errors": [
        {
            "field": "name",
            "message": "Expected string, received null"
        }
    ]
}

Example cURL

curl --location --request POST 'http://localhost:4000/api/v1/museums/1/categories' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI...t9CJfajntlpL3WRzd4' \
--header 'Content-Type: application/json' \
--data-raw '{
    "description": "Sculptures",
    "name": "Description about the sculptures category"
}'
PUT /museums/:museumId/categories/:categoryId Update category data (ADMIN)
USER MUST BE AN ADMIN

PUT create a new museum

Updates museum values in database and returns an object with the updated values.

Headers

name type data type description
Authorization required string Token must be a bearer token

Parameters

name type data type description
museumId required number The id of the museum
categoryId required number The id of the category

JSON body parameters

name type data type description
name required string Title of the museum
description required string Description of the museum

Responses

HTTP Code Content-Type Response
200 application/json
{
    "category": {
        "id": 32,
        "createdAt": "2023-10-15T19:31:08.794Z",
        "name": "Sculptures2",
        "description": "Sculptures from 91th century.",
        "museumId": 2,
        "imageUrl": null
    }
}
401 application/json
{
    "errors": [
        "Invalid access token"
    ]
}
404 application/json
{
    "errors": [
        "Category not found!"
    ]
}
422 application/json
{
    "errors": [
        {
            "field": "name",
            "message": "Expected string, received null"
        }
    ]
}

Example cURL

curl --location --request PUT 'http://localhost:4000/api/v1/museums/1/categories/32' \
--header 'Authorization: Bearer eyJhbGciOi...ntlpL3WRzd4' \
--header 'Content-Type: application/json' \
--data-raw '{
    "description": "Sculptures from 91th century.",
    "name": "Sculptures2",
    "museumId": 2
}'
DELETE /museums/:museumId/categories/:categoryId Delete a category(ADMIN)
USER MUST BE AN ADMIN

DELETE a museum

Deletes a museum and all categories and items within those categories.

Headers

name type data type description
Authorization required string Token must be a bearer token

Parameters

name type data type description
museumId required number The id of the museum
categoryId required number The id of the category

Responses

HTTP Code Content-Type Response
204
401 application/json
{
    "errors": [
        "Invalid access token"
    ]
}
404 application/json
{
    "errors": [
        "Category not found!"
    ]
}
422 application/json
{
    "errors": [
        {
            "field": "categoryId",
            "message": "Expected number, received nan"
        }
    ]
}

Example cURL

curl --location --request DELETE 'http://localhost:4000/api/v1/museums/2/categories/32' \
--header 'Authorization: Bearer eyJhbGciOiJ...jntlpL3WRzd4'

Items

GET /museums/:museumId/categories/:categoryId/items Get a list of museum category items

GET museum category items

Query parameters

name type data type description
page optional number Page number (page ∈ ℕ)
pageSize optional number Amount of items per page (pageSize ∈ ℕ ∩ [5,30])

Responses

HTTP Code Content-Type Response
200 application/json
{
    "items": [
        {
            "id": 35,
            "title": "painting1",
            "description": "This is an incredible painting",
            "imageUrl": null,
            "categoryId": 30
        },
        {
            "id": 36,
            "title": "painting2",
            "description": "This is an incredible painting2",
            "imageUrl": null,
            "categoryId": 30
        },
        {
            "id": 37,
            "title": "painting3",
            "description": "This is an incredible painting3",
            "imageUrl": null,
            "categoryId": 30
        }
    ],
    "hasNext": false
}
422 application/json
{
    "errors": [
        {
            "field": "page",
            "message": "Expected number, received nan"
        }
    ]
}

Example cURL

curl --location --request GET 'http://localhost:4000/api/v1/museums/7/categories/30/items'
GET /museums/:museumId/categories/:categoryId Get a single category

GET a category

Parameters

name type data type description
museumId required number The id of the museum
categoryId required number The id of the category

Responses

HTTP Code Content-Type Response
200 application/json
{
    "category": {
        "id": 30,
        "createdAt": "2023-10-15T19:15:15.003Z",
        "name": "Paintings",
        "description": "Until recently, the prevailing view assumed lorem ipsum was born as a nonsense text.",
        "museumId": 7,
        "imageUrl": null,
        "museum": {
            "name": "Rijksmuseum"
        }
    },
    "canEdit": false
}
404 application/json
{
    "errors": [
        "Category not found!"
    ]
}
422 application/json
{
    "errors": [
        {
            "field": "categoryId",
            "message": "Expected number, received nan"
        }
    ]
}

Example cURL

curl --location --request GET 'http://localhost:4000/api/v1/museums/7/categories/30'
POST /museums/:museumId/categories Create a new category(ADMIN)
USER MUST BE AN ADMIN

POST create a new category

Headers

name type data type description
Authorization required string Token must be a bearer token

Parameters

name type data type description
museumId required number The id of the museum

JSON body parameters

name type data type description
name required string Title of the museum
description required string Description of the museum

Responses

HTTP Code Content-Type Response
201 application/json
{
    "category": {
        "id": 31,
        "createdAt": "2023-10-15T19:27:02.734Z",
        "name": "Description about the sculptures category",
        "description": "Sculptures",
        "museumId": 1,
        "imageUrl": null
    }
}
401 application/json
{
    "errors": [
        "Invalid access token"
    ]
}
422 application/json
{
    "errors": [
        {
            "field": "name",
            "message": "Expected string, received null"
        }
    ]
}

Example cURL

curl --location --request POST 'http://localhost:4000/api/v1/museums/1/categories' \
--header 'Authorization: Bearer eyJhbGciOiJIUzI...t9CJfajntlpL3WRzd4' \
--header 'Content-Type: application/json' \
--data-raw '{
    "description": "Sculptures",
    "name": "Description about the sculptures category"
}'
PUT /museums/:museumId/categories/:categoryId Update category data (ADMIN)
USER MUST BE AN ADMIN

PUT create a new museum

Updates museum values in database and returns an object with the updated values.

Headers

name type data type description
Authorization required string Token must be a bearer token

Parameters

name type data type description
museumId required number The id of the museum
categoryId required number The id of the category

JSON body parameters

name type data type description
name required string Title of the museum
description required string Description of the museum

Responses

HTTP Code Content-Type Response
200 application/json
{
    "category": {
        "id": 32,
        "createdAt": "2023-10-15T19:31:08.794Z",
        "name": "Sculptures2",
        "description": "Sculptures from 91th century.",
        "museumId": 2,
        "imageUrl": null
    }
}
401 application/json
{
    "errors": [
        "Invalid access token"
    ]
}
404 application/json
{
    "errors": [
        "Category not found!"
    ]
}
422 application/json
{
    "errors": [
        {
            "field": "name",
            "message": "Expected string, received null"
        }
    ]
}

Example cURL

curl --location --request PUT 'http://localhost:4000/api/v1/museums/1/categories/32' \
--header 'Authorization: Bearer eyJhbGciOi...ntlpL3WRzd4' \
--header 'Content-Type: application/json' \
--data-raw '{
    "description": "Sculptures from 91th century.",
    "name": "Sculptures2",
    "museumId": 2
}'
DELETE /museums/:museumId/categories/:categoryId Delete a category(ADMIN)
USER MUST BE AN ADMIN

DELETE a museum

Deletes a museum and all categories and items within those categories.

Headers

name type data type description
Authorization required string Token must be a bearer token

Parameters

name type data type description
museumId required number The id of the museum
categoryId required number The id of the category

Responses

HTTP Code Content-Type Response
204
401 application/json
{
    "errors": [
        "Invalid access token"
    ]
}
404 application/json
{
    "errors": [
        "Category not found!"
    ]
}
422 application/json
{
    "errors": [
        {
            "field": "categoryId",
            "message": "Expected number, received nan"
        }
    ]
}

Example cURL

curl --location --request DELETE 'http://localhost:4000/api/v1/museums/2/categories/32' \
--header 'Authorization: Bearer eyJhbGciOiJ...jntlpL3WRzd4'

Listing existing stubs & proxy configs as YAML string

GET / (gets all in-memory stub & proxy configs)
Parameters

None

Responses
http code content-type response
200 text/plain;charset=UTF-8 YAML string
Example cURL
 curl --location 'http://localhost:4000/api/v1/museums' \

--header 'Content-Type: application/json'
--header 'Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6MSwicm9sZSI6IkFETUlOIiwiaWF0IjoxNjk1ODE5MjAyLCJpc3MiOiJzZXJ2ZXIiLCJhdWQiOiJ1c2VyIiwiZXhwIjoxNjk1ODI2NDAyNzUxfQ.OfXFX_XvHEBsKrXY3VW3OixmV4vIZgS_kLNu6CSaujo'
--data '{

"description": "Museum description very large building lots and lots of items and categories"

}'

GET /{stub_numeric_id} (gets stub by its resource-id-{stub_numeric_id} in the YAML config)
Parameters
name type data type description
stub_numeric_id required int ($int64) The specific stub numeric id
Responses
http code content-type response
200 text/plain;charset=UTF-8 YAML string
400 application/json {"code":"400","message":"Bad Request"}
Example cURL
 curl -X GET -H "Content-Type: application/json" http://localhost:8889/0
GET /{uuid} (gets stub by its defined uuid property)
Parameters
name type data type description
uuid required string The specific stub unique idendifier
Responses
http code content-type response
200 text/plain;charset=UTF-8 YAML string
400 application/json {"code":"400","message":"Bad Request"}
Example cURL
 curl -X GET -H "Content-Type: application/json" http://localhost:8889/some-unique-uuid-string
GET /proxy-config/default (gets default proxy-config)
Parameters

None

Responses
http code content-type response
200 text/plain;charset=UTF-8 YAML string
400 application/json {"code":"400","message":"Bad Request"}
Example cURL
 curl -X GET -H "Content-Type: application/json" http://localhost:8889/proxy-config/default
GET /proxy-config/{uuid} (gets proxy config by its uuid property)
Parameters
name type data type description
uuid required string The specific proxy config unique idendifier
Responses
http code content-type response
200 text/plain;charset=UTF-8 YAML string
400 application/json {"code":"400","message":"Bad Request"}
Example cURL
 curl -X GET -H "Content-Type: application/json" http://localhost:8889/proxy-config/some-unique-uuid-string

Updating existing stubs & proxy configs

PUT /{stub_numeric_id} (updates stub by its resource-id-{stub_numeric_id} in the config)
Parameters
name type data type description
stub_numeric_id required int ($int64) The specific stub numeric id
Responses
http code content-type response
201 text/plain;charset=UTF-8 Stub request index#<stub_numeric_id> updated successfully"
400 application/json {"code":"400","message":"Bad Request"}
405 text/html;charset=utf-8 None
Example cURL
 curl -X PUT -H "Content-Type: application/json" --data @put.json http://localhost:8889/0
PUT /{uuid} (updates stub by its defined uuid property)
Parameters
name type data type description
uuid required string The specific stub unique idendifier
Responses
http code content-type response
201 text/plain;charset=UTF-8 Stub request uuid#<uuid> updated successfully
400 application/json {"code":"400","message":"Bad Request"}
405 text/html;charset=utf-8 None
Example cURL
 curl -X PUT -H "Content-Type: application/json" --data @put.json http://localhost:8889/some-unique-uuid-string
PUT /proxy-config/default (updates default proxy-config)
Parameters

None

Responses
http code content-type response
201 text/plain;charset=UTF-8 Proxy config uuid#default updated successfully
400 application/json {"code":"400","message":"Bad Request"}
405 text/html;charset=utf-8 None
Example cURL
 curl -X PUT -H "Content-Type: application/json" --data @put.json http://localhost:8889/proxy-config/default
PUT /proxy-config/{uuid} (updates proxy-config by its uuid property)
Parameters
name type data type description
uuid required string The specific proxy config unique idendifier
Responses
http code content-type response
201 text/plain;charset=UTF-8 Proxy config uuid#<uuid> updated successfully
400 application/json {"code":"400","message":"Bad Request"}
405 text/html;charset=utf-8 None
Example cURL
 curl -X PUT -H "Content-Type: application/json" --data @put.json http://localhost:8889/proxy-config/some-unique-uuid-string

Deleting existing stubs & proxy configs

DELETE / (deletes all in-memory stub & proxy configs)
Parameters

None

Responses
http code content-type response
200 text/plain;charset=UTF-8 All in-memory YAML config was deleted successfully
Example cURL
 curl -X DELETE -H "Content-Type: application/json" http://localhost:8889/
DELETE /{stub_numeric_id} (deletes stub by its resource-id-{stub_numeric_id} in the config)
Parameters
name type data type description
stub_numeric_id required int ($int64) The specific stub numeric id
Responses
http code content-type response
200 text/plain;charset=UTF-8 Stub request index#<stub_numeric_id> deleted successfully
400 application/json {"code":"400","message":"Bad Request"}
Example cURL
 curl -X DELETE -H "Content-Type: application/json" http://localhost:8889/0
DELETE /{uuid} (updates stub by its defined uuid property)
Parameters
name type data type description
uuid required string The specific stub unique idendifier
Responses
http code content-type response
200 text/plain;charset=UTF-8 Stub request uuid#<uuid> deleted successfully
400 application/json {"code":"400","message":"Bad Request"}
Example cURL
 curl -X DELETE -H "Content-Type: application/json" http://localhost:8889/some-unique-uuid-string
DELETE /proxy-config/{uuid} (deletes proxy-config by its uuid property)
Parameters
name type data type description
uuid required string The specific proxy config unique idendifier
Responses
http code content-type response
200 text/plain;charset=UTF-8 Proxy config uuid#<uuid> deleted successfully
400 application/json {"code":"400","message":"Bad Request"}
Example cURL
 curl -X DELETE -H "Content-Type: application/json" http://localhost:8889/proxy-config/some-unique-uuid-string

Clone this wiki locally