Skip to content

Commit

Permalink
Merge pull request #4 from angelo-v/3-create-a-new-movie
Browse files Browse the repository at this point in the history
add a movies collection with the ability to create a new movie
  • Loading branch information
tpluscode authored May 7, 2019
2 parents 60a58bb + 2b45403 commit d47c0b8
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 20 deletions.
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');
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/"
}
]
}
61 changes: 53 additions & 8 deletions movies/src/resources/doc.jsonld
Original file line number Diff line number Diff line change
@@ -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."
}
]
}
]
}
}
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"
]
}
}

0 comments on commit d47c0b8

Please sign in to comment.