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

Documentation rework & mu.semte.ch import #5

Open
wants to merge 57 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
6b90873
Added reactive-programming and why-semantic-tech
Denperidge Jan 23, 2023
645a3a1
Added experimentation, fixed Aad's name (sorry)
Denperidge Jan 23, 2023
cfe2cbe
Imported oslo2 writeup
Denperidge Jan 23, 2023
bb26b84
Renamed explanations to discussions
Denperidge Jan 24, 2023
bf38b01
Imported mu.semte.ch as the ideal playground
Denperidge Jan 24, 2023
2086c07
Added reference navigation to root README
Denperidge Jan 24, 2023
df1c275
Imported Semantic Micro Services, Why Bother?
Denperidge Jan 24, 2023
359252f
Imported Find your way through the stack
Denperidge Jan 24, 2023
bd7ab3d
Added reference/documentation
Denperidge Jan 24, 2023
ccf85af
Imported how-to, fixed incorrect adapted location
Denperidge Jan 24, 2023
99980db
Added representing-logged-in-users
Denperidge Jan 25, 2023
0c6b603
Renamed reference to references
Denperidge Jan 25, 2023
7bdbc3b
Imported How mu.semte.ch can help you beat the 10%
Denperidge Jan 26, 2023
63c7c5f
Fixed link to smaller & readable code
Denperidge Jan 26, 2023
f304005
Writeup nav & imported mu.semte.ch at DockerCon EU
Denperidge Jan 26, 2023
0058f86
Imported Publishing ... Docker multi-stage builds
Denperidge Jan 26, 2023
8411177
Imported Hello MacOS
Denperidge Jan 26, 2023
a09e683
Imported mu.semte.ch at DeveloperWeek
Denperidge Jan 26, 2023
b86dad8
Imported On sharing authorization
Denperidge Jan 26, 2023
815451c
Imported On microservice reuse and authorization
Denperidge Jan 26, 2023
36cf778
Added archive README, archived Get to know mu-cl-
Denperidge Jan 26, 2023
bc2f716
Archived The delta service and its benefits
Denperidge Jan 26, 2023
2361366
Archived Auto-expanding uploaded semantic files
Denperidge Jan 26, 2023
e98389b
Imported Thoughts on how a distributed SPARQL endp
Denperidge Jan 26, 2023
11b49ff
Imported Publications from mu.semte.ch/components/
Denperidge Jan 26, 2023
4eee2da
Imported mu.semte.ch/who/
Denperidge Jan 26, 2023
2474862
Imported mu.semte.ch/about/
Denperidge Jan 26, 2023
0f0b07f
Changed link from blogpost to documentation
Denperidge Jan 26, 2023
e06005a
renamed how-to to how-tos
Denperidge Jan 26, 2023
320d497
Imported How to build a microservice template
Denperidge Mar 9, 2023
0e3e875
Fixed template documentation formatting
Denperidge Mar 9, 2023
4db6dea
Documented helper functions, added header table
Denperidge Mar 9, 2023
3cc218c
Add How-to for troubleshooting slow starting containers
piemonkey Sep 13, 2023
ac6288f
Merge pull request #1 from piemonkey/cpu-troubleshoot
Denperidge Sep 13, 2023
c0135b6
Small README.md changes, documented documentation
Denperidge Sep 22, 2023
5a6e2d1
README update, fixed typos + expanded doc-structure
Denperidge Oct 5, 2023
2079fce
Imported masterclass 01 - How and why pt1-2
Denperidge Oct 9, 2023
8c4d641
Merge branch 'master' into masterclass
Denperidge Oct 14, 2023
9d88d52
Imported masterclass 02 - A shared foundation pt1
Denperidge Oct 14, 2023
fee309f
Imported masterclass 04 - Templates and conventions*
Denperidge Oct 15, 2023
5a63787
Imported masterclass 05 - Common microservices pt1-3
Denperidge Oct 15, 2023
c6ae872
Added extra notes from blog post to TODO.md
Denperidge Oct 15, 2023
9ef0205
Deprecations & refactors
Denperidge Oct 16, 2023
797e070
Writeups structure refactor
Denperidge Oct 16, 2023
b607190
Merged building-a-template into creating-templates
Denperidge Oct 16, 2023
6b9c9cb
Merged naming-conventions into project categories
Denperidge Oct 16, 2023
f4324f5
Slight README changes, renamed references-reference
Denperidge Oct 16, 2023
f419e2a
Deprecations & refactors
Denperidge Oct 16, 2023
5c15fd8
Merge pull request #2 from Denperidge-Redpencil/masterclass
Denperidge Oct 16, 2023
8e913f4
why-semantic-*: deprecate & import, README update
Denperidge Oct 16, 2023
91f4b8f
Added explainers with getting started
Denperidge Oct 18, 2023
584d5a2
Design philosophy polish
Denperidge Oct 18, 2023
f6e345a
Merge branch 'deprecations-and-refactors'
Denperidge Oct 18, 2023
c19996e
Fixed outdated relative links
Denperidge Oct 19, 2023
64b7fd5
Merge branch 'master' of https://github.com/Denperidge-Redpencil/project
Denperidge Oct 19, 2023
b82bc79
Update quickstart-writing-documentation.md
Denperidge Oct 28, 2023
fd84cd5
Fixed typo
Denperidge Oct 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merged building-a-template into creating-templates
  • Loading branch information
Denperidge committed Oct 16, 2023
commit b607190eda9ae92c6b1ee3e80af3d0d21985a3da
181 changes: 0 additions & 181 deletions docs/tutorials/building-a-template.md

This file was deleted.

159 changes: 152 additions & 7 deletions docs/tutorials/creating-templates.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
# Template requirements
# Creating templates

## PoC (proof of concept) requirements
## The importance of templates
Templates...
- ... make it easier to implement new microservices
- ... help you get started with the technology you know and love, or help you understand the structure of a service written in a technology/language you barely know
- ... should be predictable. The naming and structure of templates
should therefore match certain standards
- ... make it easy to follow the constraints semantic.works places on services, and should therefore contain a basic set of features which ensures users can easily develop applications in them


Templates are our way to familiarize users with semantic.works and to ensure users follow the best practices where possibl

## The steps of developing a template
A template should make sure that the semantic.works ecosystem keeps
running. The construction of a template happens in a set of stages.

Building a template without knowing the domain is near impossible.

### Step 1: Basic service
First one should implement a basic service in the base technology, to get a feeling of which technologies are suited for the template

To begin, select the technology you would like to support. Look around for web frameworks which match the ideology of microservices. Search for the 'Ruby Sinatra' competitor for your language.

Your next challenge is to implement a simple microservice for this
purpose. As an example, you can write a service that returns the amount of Tasks in the store, and which allows you to set a Task as done. The service itself is not of importance, you'll learn lessons about the framework when you implement the microservice.

Don't forget to run your microservice in a toy semantic.works project.
That way you'll know that it actually works.
[mu-project](https://github.com/mu-semtech/mu-project)
offers a good starting point.

### Step 2: PoC (Proof of Concept)
Next up is the construction of a PoC (Proof of Concept).

Once your service works, you can start abstracting it. Much of the code you've built would be used again when you implement another service in the same language. Go over the list of the PoC, ensure you've implemented each feature, and put this in a separate project. This project will become the template to use for the Tasks service. If all goes well, you'll end with a PoC template service, and a much shorter Tasks service.

#### PoC requirements
- Respond to HTTP requests
- Parse JSON & JSONAPI payloads
- Support implementation of GET PUT PATCH POST DELETE
Expand All @@ -19,9 +54,20 @@
- Load user-code from `/app`
- Download & install dependencies on startup

## Full template requirements

- [**All requirements for the PoC**](#poc-proof-of-concept-requirements)
### Step 3: Full template
Then comes the standardisation, which requires some extra features to ensure the template can be used in practice.

This includes going over the [list of features needed for the full template](#full-requirements).
Go over the list of features and try to implement them in a clean
fashion. More complex, and realistic microservices, like those
automatically creating Tasks for all starred books you haven't read yet now become possible. This is the space where your microservice should be in.

Document the use of the microservice, and get us to publish it on our GitHub space.

#### Full requirements

- [**All requirements for the PoC**](#poc-requirements)

- Configuration
- Access environment variables [[2]](#notes)
Expand Down Expand Up @@ -51,7 +97,103 @@
- Enable debugging symbols (if possible)
- Enable error output (if configurable)

## Helper functions

## Extra considerations
### Levels of abstraction

Most developers like to abstract things. Make sure that nothing is
repeated. Many of us like to get started quickly. These two ideas often don't go hand-in-hand. We dismiss non-generic abstractions and require consistent naming.

Getting started should be trivial and has the highest priority. It
should be intuitive to start using a new template. It should be easy to read code that was written in a template, even if it isn't yours.

The following is a description of various topics on which consistency should be held. The description should be adapted to the use of your language. Ie: if you'd call sparql_query in Ruby, sparqlQuery in Java and sparql-query in Common Lisp.

#### Defining HTTP endpoints

Users will define HTTP endpoints to which their service will respond.
Separate methods should be defined for separate types of call. The
method should simply contain the name of HTTP verb, and the URL to which we respond. The system should allow the user to destructure the input and access the destructured contents. Calls may be defined in a block, but if that is the case, then the block should be repeatable.

**Essentials:**
- Use simple name of HTTP verb
- Allow straight-forward destructuring of URL
- Support finding query parameters

Example in Common Lisp:

```lisp
(defcall :get (“say” “hello” “to” name)
;; responds to GET /say/hello/to/Aad?title=Sir
;; name is bound to Aad
;; (get-parameter “title”) yields “Sir”
)

```

Example in Ruby:
```ruby
get “say/hello/to/:name” do |name|
# responds to GET /say/hello/to/Erika?title=Madam
# name is bound to erika
# params[:title] yields “Madam”
end

```

Another example in Ruby:
```ruby
define_calls do |server|
server.get “say/hello/to/:name” do |name|
# responds to GET /say/hello/to/Erika?title=Madam
# name is bound to erika
# params[:title] yields “Madam”
end
end
```

#### Executing SPARQL queries

We should mitigate SPARQL-injection whilst still ensuring the SPARQL
queries are easy to recognise. Allow for injecting variables in a
SPARQL-query string. Support escaping as separate methods. Query results
should be parsed automatically so the user can easily process them.

A SPARQL endpoint often differs in query and update endpoints. Hence we
advise to use those two names for executing the queries.

For languages which don't allow injecting variables into strings, magic
is allowed. Keep it to an absolute minimum and try to mimic what is
commonly found in other languages. It should be something which you can
explain in a single sentence.

Common Lisp example:
```lisp
(sparql-query “SELECT ?s ?p ?o WHERE
GRAPH <http://mu.semte.ch/application> {
?s a foaf:Agent;
foaf:name ~A;
?p ?o.
}”, (sparql-escape-string “Felix”))

(sparql-update “INSERT DATA
GRAPH <http://mu.semte.ch/application> {
ext:Aad a foaf:Agent.
}”)
```
J

Ruby example:
```ruby
query “SELECT ?s ?p ?o WHERE
GRAPH <http://mu.semte.ch/application> {
?s a foaf:Agent;
foaf:name #{username.sparql_escape};
?p ?o.
}”
```

### 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.
Expand All @@ -68,7 +210,7 @@ needed or wanted.

*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
#### 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.
Expand All @@ -85,7 +227,7 @@ This functions should be used especially when inserting user-input to avoid SPAR
| sparql_escape_datetime | value: `datetime` |
| sparql_escape_bool | value: `bool` |

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

| Header name | Type | Description |
Expand All @@ -96,6 +238,9 @@ The following headers should be passed when making queries:
| MU-AUTH-USED-GROUPS | | |





## Notes

1. This constraint should be dropped in the distant future, but it is
Expand Down