diff --git a/movies/Makefile b/movies/Makefile index 4028a5b..5517de0 100644 --- a/movies/Makefile +++ b/movies/Makefile @@ -1,12 +1,14 @@ +APP ?= hydra-movies + image: ## build image and push to heroku registry - heroku container:push web --app hydra-movies + heroku container:push web --app $(APP) release: ## release container to heroku - heroku container:release web --app hydra-movies + heroku container:release web --app $(APP) deploy: image release logs: ## show heroku logs - heroku logs --tail --app hydra-movies + heroku logs --tail --app $(APP) .PHONY: image release deploy logs diff --git a/movies/docs/deployment.md b/movies/docs/deployment.md index 48ce5c7..22c2266 100644 --- a/movies/docs/deployment.md +++ b/movies/docs/deployment.md @@ -11,4 +11,19 @@ Afterwards run the follwing command within the `movies` directory: ```bash make deploy -``` \ No newline at end of file +``` + +### Deploy to your own account + +You can deploy to your own heroku account. First log in: + + ```bash + heroku login + heroku container:login + ``` + +Then run `make` with specifying the `APP` name: + +```bash +make APP=my-hydra-movies deploy +``` diff --git a/movies/src/index.js b/movies/src/index.js index ded3f3b..ff9f0bb 100644 --- a/movies/src/index.js +++ b/movies/src/index.js @@ -4,4 +4,16 @@ const port = process.env.PORT || 3000; app.listen(port, function () { console.log(`Example API listening on port ${port}!`); -}); \ No newline at end of file +}); + +app.post('/movies', (req, res) => { + res.status(201); + res.setHeader('Location', '/movies/d517cae6-6cdc-11e9-a923-1681be663d3e'); + res.setHeader('Content-Type', 'application/ld+json'); + res.send({ + "@context": "/context.jsonld", + "@id": "/movies/d517cae6-6cdc-11e9-a923-1681be663d3e", + "@type": "schema:Movie", + "schema:name": "Fake Movie" + }); +}); diff --git a/movies/src/resources/context.jsonld b/movies/src/resources/context.jsonld index 817440c..63fbac4 100644 --- a/movies/src/resources/context.jsonld +++ b/movies/src/resources/context.jsonld @@ -1,6 +1,9 @@ { - "@context": { - "hydra": "http://www.w3.org/ns/hydra/core#", - "schema": "http://schema.org/" - } -} \ No newline at end of file + "@context": [ + "https://www.w3.org/ns/hydra/core", + { + "mov": "https://hydra-movies.herokuapp.com/doc#", + "schema": "http://schema.org/" + } + ] +} diff --git a/movies/src/resources/doc.jsonld b/movies/src/resources/doc.jsonld index ec55772..d65354d 100644 --- a/movies/src/resources/doc.jsonld +++ b/movies/src/resources/doc.jsonld @@ -1,15 +1,60 @@ { "@context": "/context.jsonld", "@id": "/doc", - "@type": "hydra:ApiDocumentation", - "hydra:title": "Hydra Movies API", - "hydra:description": "This API shows how a basic CRUD (Create, Read, Update, Delete) API can be designed using Hydra Core Vocabulary.", - "hydra:entrypoint": "/", - "hydra:supportedClass": [ + "@type": "ApiDocumentation", + "title": "Hydra Movies API", + "description": "This API shows how a basic CRUD (Create, Read, Update, Delete) API can be designed using Hydra Core Vocabulary.", + "entrypoint": "/", + "supportedClass": [ + { + "@id": "schema:EntryPoint", + "@type": "Class", + "title": "API entrypoint", + "description": "Every capability of the API can be reached from here by following links." + }, + { + "@id": "mov:Movies", + "@type": "Class", + "title": "Movies", + "description": "Allows to access and manage movies that are available via the API.", + "supportedOperation": { + "@id": "mov:create-movie", + "@type": [ "Operation", "schema:CreateAction" ], + "title": "Create movie", + "description": "Creates a new movie", + "method": "POST", + "expects": "schema:Movie", + "returns": "schema:Movie", + "possibleStatus": [ + { + "statusCode": 201, + "description": "If the movie was created successfully." + } + ] + } + }, { "@id": "schema:Movie", - "@type": "hydra:Class", - "hydra:title": "A movie" + "@type": "Class", + "title": "Movie", + "description": "A single movie", + "supportedProperty": [ + { + "property": "schema:name", + "title": "name", + "description": "The movie's name" + }, + { + "property": "schema:description", + "title": "description", + "description": "Textual description of the movie." + }, + { + "property": "schema:duration", + "title": "duration", + "description": "The movie's duration in ISO 8601 date format." + } + ] } ] -} \ No newline at end of file +} diff --git a/movies/src/resources/index.jsonld b/movies/src/resources/index.jsonld index e2d064f..0d9f42b 100644 --- a/movies/src/resources/index.jsonld +++ b/movies/src/resources/index.jsonld @@ -1,5 +1,12 @@ { "@context": "/context.jsonld", "@id": "/", - "@type": "hydra:Entrypoint" -} \ No newline at end of file + "@type": "schema:EntryPoint", + "collection": { + "@id": "movies", + "@type": [ + "Collection", + "mov:Movies" + ] + } +}