|
17 | 17 | --> |
18 | 18 |
|
19 | 19 | <html> |
| 20 | + <head> |
| 21 | + <meta charset="utf-8" /> |
| 22 | + <title>API Level 0 Example - Node.js</title> |
20 | 23 |
|
21 | | -<head> |
| 24 | + <link |
| 25 | + rel="stylesheet" |
| 26 | + href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" |
| 27 | + integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" |
| 28 | + crossorigin="anonymous" |
| 29 | + /> |
| 30 | + </head> |
22 | 31 |
|
23 | | - <meta charset="utf-8"> |
24 | | - <title>API Level 0 Example - Node.js</title> |
| 32 | + <body> |
| 33 | + <div class="container" id="app"> |
| 34 | + <div> |
| 35 | + <h1>API Level 0 Example - Node.js</h1> |
| 36 | + <p class="lead"> |
| 37 | + This example showcases a basic mapping of a business operation to a |
| 38 | + remote endpoint. By taking this approach, clients leverage the HTTP |
| 39 | + protocol as a transport mechanism to call upon services. Application |
| 40 | + engineers define their APIs using a broad interpretation of REST |
| 41 | + fundamentals, encouraging freedom in design and quick prototyping. |
| 42 | + </p> |
25 | 43 |
|
26 | | - <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" |
27 | | - integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> |
| 44 | + <h2>Using the greeting service</h2> |
28 | 45 |
|
29 | | -</head> |
| 46 | + <form class="form-inline" @submit.prevent="getJSON"> |
| 47 | + <div class="form-group"> |
| 48 | + <label for="name">Name</label> |
| 49 | + <input |
| 50 | + type="text" |
| 51 | + ref="name" |
| 52 | + class="form-control" |
| 53 | + id="name" |
| 54 | + placeholder="World" |
| 55 | + /> |
| 56 | + </div> |
| 57 | + <button id="invoke" type="submit" class="btn btn-success"> |
| 58 | + Invoke |
| 59 | + </button> |
| 60 | + </form> |
30 | 61 |
|
31 | | -<body> |
32 | | - |
33 | | -<div class="container"> |
34 | | - |
35 | | - <div> |
36 | | - <h1>API Level 0 Example - Node.js</h1> |
37 | | - <p class="lead">This example showcases a basic mapping of a business operation to a remote endpoint. By |
38 | | - taking this approach, clients leverage the HTTP protocol as a transport mechanism to call upon services. |
39 | | - Application engineers define their APIs using a broad interpretation of REST fundamentals, encouraging |
40 | | - freedom in design and quick prototyping. |
41 | | - </p> |
42 | | - |
43 | | - <h2>Using the greeting service</h2> |
44 | | - |
45 | | - <form class="form-inline"> |
46 | | - <div class="form-group"> |
47 | | - <label for="name">Name</label> |
48 | | - <input type="text" class="form-control" id="name" placeholder="World"> |
| 62 | + <h3>Result:</h3> |
| 63 | + <pre><code id="greeting-result">{{greetingResult}}</code></pre> |
49 | 64 | </div> |
50 | | - <button id="invoke" type="submit" class="btn btn-success">Invoke</button> |
51 | | - </form> |
52 | | - |
53 | | - <h3>Result:</h3> |
54 | | - <pre><code id="greeting-result">Invoke the service to see the result.</code></pre> |
55 | | - </div> |
56 | | -</div> |
57 | | - |
58 | | -<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> |
59 | | -<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" |
60 | | - integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" |
61 | | - crossorigin="anonymous"></script> |
62 | | - |
63 | | -<script> |
64 | | - $(document).ready(() => { |
65 | | - $("#invoke").click((e) => { |
66 | | - const n = $("#name").val() || "World"; |
67 | | - $.getJSON(`/api/greeting?name=${n}`, (res) => { |
68 | | - $("#greeting-result").html(JSON.stringify(res)); |
69 | | - }); |
70 | | - e.preventDefault(); |
71 | | - }); |
72 | | - }); |
73 | | -</script> |
74 | | - |
75 | | -</body> |
76 | | - |
| 65 | + </div> |
| 66 | + <script |
| 67 | + src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.7.10/vue.min.js" |
| 68 | + integrity="sha512-H8u5mlZT1FD7MRlnUsODppkKyk+VEiCmncej8yZW1k/wUT90OQon0F9DSf/2Qh+7L/5UHd+xTLrMszjHEZc2BA==" |
| 69 | + crossorigin="anonymous" |
| 70 | + referrerpolicy="no-referrer" |
| 71 | + ></script> |
| 72 | + <script> |
| 73 | + const app = new Vue({ |
| 74 | + el: "#app", |
| 75 | + data: { |
| 76 | + greetingResult: "Invoke the service to see the result.", |
| 77 | + }, |
| 78 | + methods: { |
| 79 | + async getJSON(e) { |
| 80 | + const name = this.$refs.name.value; |
| 81 | + const result = await fetch(`/api/greeting?name=${name}`); |
| 82 | + if (!result.ok) { |
| 83 | + const message = `Error: ${result.status} - ${result.statusText}`; |
| 84 | + throw new Error(message); |
| 85 | + } |
| 86 | + const data = await result.json(); |
| 87 | + this.greetingResult = JSON.stringify(data); |
| 88 | + }, |
| 89 | + }, |
| 90 | + }); |
| 91 | + </script> |
| 92 | + </body> |
77 | 93 | </html> |
0 commit comments