forked from m-reza-rahman/jakartaee-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackend.html
More file actions
75 lines (75 loc) · 3.72 KB
/
Copy pathbackend.html
File metadata and controls
75 lines (75 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<html>
<head>
<title>Java EE as JavaScript Backend</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<h2>Java EE as JavaScript Backend</h2>
<p>The JavaScript backend consists of a chat WebSocket API
and a to do list REST API implemented using the Java
API for WebSocket, JSON-P, JAX-RS 2 and Java EE 7.</p>
<p>Note that while the endpoints in this application are not fully secured
but uses TLS/SSL, in a real application they should be secured, likely using
some sort of federated security scheme.</p>
<p>The WebSocket chat endpoint is at:
<a href="wss://localhost:8181/javaee-javascript/chat">
wss://localhost:8181/javaee-javascript/chat</a>. The
endpoint communicates via JSON. Once connected, a client
can send a chat message using this format:
<pre>
{"user": "the name of the user",
"message": "the chat message"}
</pre>
Each chat message sent to the server will be echoed back to all
currently connected clients including the client that sent the
message. The server will also include the timestamp on the server
when the message was received. The chat messages echoed back
from the server will follow this format:
<pre>
{"user": "the name of the user that sent the message",
"message": "the echoed chat message",
"timestamp": "the server timestamp - MM/dd/yyyy h:mm:ss a z"}
</pre>
</p>
<p>The REST endpoint is available at <a href="https://localhost:8181/javaee-javascript/resources/todo">
https://localhost:8181/javaee-javascript/resources/todo</a>. The
REST endpoint also communicates with the client using JSON.
To do items are stored under various usernames. To retrieve
the current to do items for a given user, the client must issue
a GET request to this URL: <a href="https://localhost:8181/javaee-javascript/resources/todo/{username}">
https://localhost:8181/javaee-javascript/resources/todo/{username}</a>.
The server will respond with the list of current to do items for the
user following this format:
<pre>
[{"id": "to do item ID",
"description": "item 1 description",
"completed": "true|false"},
{"id": "to do item ID",
"description": "item 2 description",
"completed": "true|false"}
...]
</pre>
To add an item for a user, the client must issue a POST request to
this URL: <a href="https://localhost:8181/javaee-javascript/resources/todo/{username}">
https://localhost:8181/javaee-javascript/resources/todo/{username}</a>.
The POST body must follow this format:
<pre>
{"description": "item description"}
</pre>
An ID will be automatically assigned and the item will be assumed to be
incomplete. The POST response will return the ID assigned to the item as plain text (not JSON).
To modify a to do item, the client must issue a PUT
request to this URL: <a href="https://localhost:8181/javaee-javascript/resources/todo/{username}/{id}">
https://localhost:8181/javaee-javascript/resources/todo/{username}/{id}</a>.
The PUT request body must follow this format:
<pre>
{"id": "to do item ID",
"description": "item description",
"completed": "true|false"}
</pre>
To delete a to do item, the client must issue a DELETE request to
this URL: <a href="https://localhost:8181/javaee-javascript/resources/todo/{username}/{id}">
https://localhost:8181/javaee-javascript/resources/todo/{username}/{id}</a>.
</p>
</body>
</html>