Skip to content

Commit

Permalink
Documented helper functions, added header table
Browse files Browse the repository at this point in the history
  • Loading branch information
Denperidge committed Mar 9, 2023
1 parent 0e3e875 commit 4db6dea
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions docs/references/template-requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,50 @@
- Enable debugging symbols (if possible)
- Enable error output (if configurable)

## Helper functions
Ideally, your template should expose some helper functions, including
but not limited to the following. Extra parameters can be added as
needed or wanted.


| Function name | Parameters | Description |
| ------------------ | --------------------- | ----------- |
| error | title: `string`, http_error_code: `int` | Returns a JSONAPI compliant error response with the given status code (default: 400). |
| query | query: `string` | Executes the given SPARQL select/ask/construct query. [This function should automatically pass the correct headers](#passing-headers). Also see `update`. |
| session_id_header | request: `object` | Get the session id from the HTTP request headers. |
| sparql_escape | value: `any` | Detects the value type and runs the appropiate [sparql escape function](#sparql_escape). |
| update | query: `string` | Executes the given SPARQL update query. [This function should automatically pass the correct headers](#passing-headers). Also see `query`. |
| uuid | None | Generates an uuid. Meant for use in linked data (`mu:uuid`). |

*Note: camelcase is used in this documentation. However, when writing the helpers in the language of your choice, use the notation that is in line with the language in question.*

### sparql_escape
The following helper functions all have the same description/funcionality, but for different types. As such, the description column is omitted.

**Description:** Converts the given object to a SPARQL-safe RDF object string with the right RDF-datatype.
This functions should be used especially when inserting user-input to avoid SPARQL-injection.

| Function name | Parameters |
| ---------------------- | ----------------- |
| sparql_escape_string | value: `string` |
| sparql_escape_uri | value: `url` |
| sparql_escape_decimal | value: `decimal` |
| sparql_escape_int | value: `int` |
| sparql_escape_float | value: `float` |
| sparql_escape_date | value: `date` |
| sparql_escape_datetime | value: `datetime` |
| sparql_escape_bool | value: `bool` |

### Passing headers
The following headers should be passed when making queries:

| Header name | Type | Description |
| ---------------------- | -------- | ----------------------- |
| MU-SESSION-ID | | |
| MU-CALL-ID | | |
| MU-AUTH-ALLOWED-GROUPS | | (bidirectional) |
| MU-AUTH-USED-GROUPS | | |


## Notes

Expand Down

0 comments on commit 4db6dea

Please sign in to comment.