You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/TUTORIAL.md
+20-1Lines changed: 20 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -108,7 +108,26 @@ Description of the code:
108
108
4.`route` declares the URL path at which the service operates. It also maps components of the URL path to handler parameters.
109
109
-`base` defines the first part of the URL that doesn't change, e.g. `/example/`.
110
110
-`pattern` defines the variable part of the route, everything that comes after `/example/`. It can include any number of named parameters. These are converted into regular expressions by [`path-to-regexp`][path-to-regexp]. Because a service instance won't be created until it's time to handle a request, the route and other metadata must be obtained by examining the classes themselves. [That's why they're marked `static`.][static]
111
-
- There is additional documentation on conventions for [designing badge URLs](./badge-urls.md)
111
+
112
+
-`routeEnum` (optional): an array of strings that defines a finite set of allowed values for an enum-like parameter in the route. When `routeEnum` is present, the first named parameter in the route `pattern` is treated as the enum value to validate against `routeEnum`.
113
+
- Example: for a route with pattern `:type/:user/:repo` you would set `static routeEnum = ['dt', 'dm', 'dd']` and the incoming `type` value will be validated against that array.
114
+
- If the first named parameter is not present in `routeEnum`, the request will be rejected before `handle()` is invoked.
// `type` is guaranteed to be one of 'dt', 'dm', or 'dd'
124
+
// implement fetch/render logic here
125
+
}
126
+
}
127
+
```
128
+
129
+
- There is additional documentation on conventions for [designing badge URLs](./badge-urls.md)
130
+
112
131
5. All badges must implement the `async handle()` function that receives parameters to render the badge. Parameters of `handle()` will match the name defined in `route` Because we're capturing a single variable called `text` our function signature is `async handle({ text })`. `async` is needed to let JavaScript do other things while we are waiting for result from external API. Although in this simple case, we don't make any external calls. Our `handle()` function should return an object with 3 properties:
113
132
-`label`: the text on the left side of the badge
114
133
-`message`: the text on the right side of the badge - here we are passing through the parameter we captured in the route regex
Copy file name to clipboardExpand all lines: doc/badge-urls.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,8 @@
5
5
- singular if the badge message represents a single entity, such as the current status of a build (e.g: `/build`), or a more abstract or aggregate representation of the thing (e.g.: `/coverage`, `/quality`)
6
6
- plural if there are (or may) be many of the thing (e.g: `/dependencies`, `/stars`)
7
7
- Parameters should always be part of the route if they are required to display a badge e.g: `:packageName` and should be lower camelCase.
8
+
- Parameters should always be part of the route if they are required to display a badge e.g: `:packageName` and should be lower camelCase.
9
+
-`routeEnum` support: when a service defines a finite set of allowed values for a parameter, the service can declare `static routeEnum = [...]`. In that case the first named parameter in the route `pattern` is treated as the enum to validate against `routeEnum`.
8
10
- Common optional params like, `:branch` or `:tag` should also be passed as part of the route.
9
11
- Query string parameters should be used when:
10
12
- The parameter is related to formatting. e.g: `/appveyor/tests/:user/:repo?compact_message`.
0 commit comments