Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a movies collection with the ability to create a new movie #4

Merged
merged 9 commits into from
May 7, 2019
8 changes: 5 additions & 3 deletions movies/Makefile
Original file line number Diff line number Diff line change
@@ -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
17 changes: 16 additions & 1 deletion movies/docs/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,19 @@ Afterwards run the follwing command within the `movies` directory:

```bash
make deploy
```
```

### 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
```
14 changes: 13 additions & 1 deletion movies/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,16 @@ const port = process.env.PORT || 3000;

app.listen(port, function () {
console.log(`Example API listening on port ${port}!`);
});
});

app.post('/movies', (req, res) => {
res.status(201);
res.setHeader('Location', '/movies/d517cae6-6cdc-11e9-a923-1681be663d3e');
tpluscode marked this conversation as resolved.
Show resolved Hide resolved
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"
});
});
13 changes: 8 additions & 5 deletions movies/src/resources/context.jsonld
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"@context": {
"hydra": "http://www.w3.org/ns/hydra/core#",
"schema": "http://schema.org/"
}
}
"@context": [
"https://www.w3.org/ns/hydra/core",
{
"mov": "https://hydra-movies.herokuapp.com/doc#",
"schema": "http://schema.org/"
}
]
}
51 changes: 43 additions & 8 deletions movies/src/resources/doc.jsonld
Original file line number Diff line number Diff line change
@@ -1,15 +1,50 @@
{
"@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": [
angelo-v marked this conversation as resolved.
Show resolved Hide resolved
{
"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"
}
]
}
]
}
}
11 changes: 9 additions & 2 deletions movies/src/resources/index.jsonld
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"@context": "/context.jsonld",
"@id": "/",
"@type": "hydra:Entrypoint"
}
"@type": "schema:EntryPoint",
"collection": {
"@id": "movies",
"@type": [
"Collection",
"mov:Movies"
]
}
}