Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
erikap committed Jan 11, 2017
1 parent 2160983 commit 2b2863c
Showing 1 changed file with 32 additions and 24 deletions.
56 changes: 32 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,42 +39,26 @@ The template provides the user with several helper methods in Sinatra. These hel
#### error(title, status = 400)
Returns a JSONAPI compliant error response with the given status code (default: `400`).

#### rewrite_url_header(request)
Get the rewrite URL from the request headers.

#### session_id_header(request)
Get the session id from the request headers.

#### validate_json_api_content_type(request)
Validate whether the Content-Type header contains the JSONAPI Content-Type. Returns a `400` otherwise.

#### validate_resource_type(expected_type, data)
Validate whether the type specified in the JSON data is equal to the expected type. Returns a `409` otherwise.

## Utils
The template provides several utils that are automatically included in the Sinatra application (`web.rb`), but they can also be used outside the Sinatra context. Just include the `SinatraTemplate::Utils` module in your file.

```
require_relative '/usr/src/app/sinatra_template/utils.rb'
include SinatraTemplate::Utils
```

The following methods are provided:

#### graph
Returns the application graph configured through the `MU_APPLICATION_GRAPH`.

#### generate_uuid()
Generate a random UUID (String).

#### log
The template provides a `log` object to the user for logging. Just do `log.info "Hello world"`. The log level can be set through the `LOG_LEVEL` environment variable (default: `info`, values: `debug`, `info`, `warn`, `error`, `fatal`).
The template provides a [Logger](https://ruby-doc.org/stdlib-2.3.0/libdoc/logger/rdoc/Logger.html) `log` object to the user for logging. Just do `log.info "Hello world"`. The log level can be set through the `LOG_LEVEL` environment variable (default: `info`, values: `debug`, `info`, `warn`, `error`, `fatal`).

Logs are written to the `/logs` directory in the docker container.
Logs are written to the `/logs` directory and `STDOUT` in the docker container.

#### query(query)
Executes the given SPARQL select/ask/construct query.

#### rewrite_url_header(request)
Get the rewrite URL from the request headers.

#### session_id_header(request)
Get the session id from the request headers.

#### sparql_client
Returns a SPARQL::Client instance connection to the SPARQL endpoint configured through the `MU_SPARQL_ENDPOINT` environment variable.

Expand All @@ -84,6 +68,30 @@ Executes the given SPARQL update query.
#### update_modified(subject, modified = DateTime.now)
Executes a SPARQL query to update the modification date of the given subject URI (string). The date defaults to now.

#### validate_json_api_content_type(request)
Validate whether the Content-Type header contains the JSONAPI Content-Type. Returns a `400` otherwise.

#### validate_resource_type(expected_type, data)
Validate whether the type specified in the JSON data is equal to the expected type. Returns a `409` otherwise.


## Helpers outside the Sinatra context
The template provides several helpers that are automatically included in the Sinatra application (`web.rb`), but some of them can also be used outside the Sinatra context. Just include the `SinatraTemplate::Utils` module in your file.

```
require_relative '/usr/src/app/sinatra_template/utils.rb'
include SinatraTemplate::Utils
```

The following [helper methods](https://github.com/mu-semtech/mu-ruby-template#helper-methods) are provided:
* graph
* generate_uuid
* log
* query(query)
* sparql_client
* update(query)
* update_modified(subject, modified = DateTime.now)


## Writing tests for your microservice
To test your app, run the container with `RACK_ENV` set to `test`. All [rspec](http://rspec.info/) tests matching `*_spec.rb` in `spec/` and its subdirectories will be executed.
Expand Down

0 comments on commit 2b2863c

Please sign in to comment.