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
defdynamic() =s"Current date is: ${ZonedDateTime.now()}"
35
+
defdynamic():String=s"Current date is: ${ZonedDateTime.now()}"
38
36
39
37
initialize()
40
38
```
41
39
{% endtab %}
42
40
{% endtabs %}
43
41
42
+
The example above creates an endpoint returning the current date and time available at `/time`. The exact response will be
43
+
recreated every time you refresh the webpage.
44
+
45
+
Since the endpoint method has `String` output type, the result will be sent with `text/plain`[content type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type).
46
+
If you want an HTML output being interpreted by the browser, you else need to set the `Content-Type` header manually
47
+
or [use the Scalatags templating library](/toolkit/web-server-dynamic.html#using-html-templates), supported by Cask.
48
+
49
+
### Running the example
44
50
45
-
Run the example the same way as before (assuming you use the same project structure).
51
+
Run the example the same way as before, assuming you use the same project structure as described in [the static file tutorial](/toolkit/web-server-static.html).
Accessing the endpoint at [http://localhost:8080/time/Paris](http://localhost:8080/time/Paris) will result with:
126
-
```
127
-
Current date is: 2024-07-22T09:08:33.806259+02:00[Europe/Paris]
128
-
```
131
+
In the example above, the `:city` segment in `/time/:city` is available through the `city` argument of the endpoint method.
132
+
The name of the argument must be identical to the segment name. The `getZoneIdForCity` helper method find the timezone for
133
+
a given city and then the current date and time is translated to that timezone.
129
134
130
-
and at [http://localhost:8080/time/Tokyo](http://localhost:8080/time/Tokyo) you will see:
135
+
Accessing [the endpoint](http://localhost:8080/time/Paris) (notice the `Paris` segment in the URL) will result with:
131
136
```
132
-
Current date is: 2024-07-22T16:08:41.137563+09:00[Asia/Tokyo]
137
+
Current date is: 2024-07-22T09:08:33.806259+02:00[Europe/Paris]
133
138
```
134
139
135
-
Cask endpoints can handle either fixed or arbitrary number of path segments. Please consult the
136
-
[documentation](https://com-lihaoyi.github.io/cask/index.html#variable-routes) for more details.
140
+
You can use more than one path segment in an endpoint by adding more arguments to the endpoint method. It's also possible to use paths
141
+
with an unspecified number of segments (for example `/path/foo/bar/baz/`) by giving the endpoint method an argument with `cask.RemainingPathSegments` type.
142
+
Consult the [documentation](https://com-lihaoyi.github.io/cask/index.html#variable-routes) for more details.
137
143
138
144
## Using HTML templates
139
145
140
-
You can combine Cask code with a templating library like [Scalatags](https://com-lihaoyi.github.io/scalatags/) to
141
-
build an HTML response.
146
+
To create an HTML response, you can combine Cask code with the [Scalatags](https://com-lihaoyi.github.io/scalatags/) templating library.
0 commit comments