Statistics
| Branch: | Tag: | Revision:

mongoose / examples / restful_server / index.html @ eaef5bd1

History | View | Annotate | Download (1.88 KB)

1
<!DOCTYPE html>
2
<html lang="en">
3
<head>
4
  <meta charset="utf-8" />
5
  <title>RESTful API demo</title>
6
  <meta name="viewport" content="width=device-width, initial-scale=1" />
7
  <style type="text/css">
8
    * { outline: none; }
9
    body {
10
      background-color: #789; margin: 0;
11
      padding: 0; font: 16px/1.4 Helvetica, Arial, sans-serif;
12
      font: 16px/1.4 Helvetica, Arial, sans-serif;
13
    }
14
    div.content {
15
      width: 800px; margin: 2em auto; padding: 20px 50px;
16
      background-color: #fff; border-radius: 1em;
17
    }
18
    label { display: inline-block; min-width: 7em; }
19
    input { border: 1px solid #ccc; padding: 0.2em; }
20
    a:link, a:visited { color: #69c; text-decoration: none; }
21
    @media (max-width: 700px) {
22
      body { background-color: #fff; }
23
      div.content { width: auto; margin: 0 auto; padding: 1em; }
24
    }
25
</style>
26

    
27
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
28
<script language="javascript" type="text/javascript">
29
  jQuery(function() {
30

31
    $(document).on('keyup', '#n1, #n2', function() {
32
      $.ajax({
33
        url: '/api/v1/sum',
34
        method: 'POST',
35
        dataType: 'json',
36
        data: { n1: $('#n1').val(), n2: $('#n2').val() },
37
        success: function(json) {
38
          $('#result').html(json.result);
39
        }
40
      });
41
    });
42

43
  });
44
</script>
45
</head>
46
<body>
47
  <div class="content">
48
    <h1>RESTful API demo.</h1>
49

    
50
    <p>
51
      This page demonstrates how Mongoose could be used to implement
52
      RESTful APIs. Start typing numbers into the text fields below.
53
      Browser sends two numbers to <tt>/api/v1/sum</tt> URI.
54
      Web server calclulates the sum and returns the result.
55
    </p>
56

    
57
    <div>
58
      <label>Number 1:</label> <input type="text" id="n1" />
59
    </div><div>
60
      <label>Number 2:</label> <input type="text" id="n2" />
61
    </div><div>
62
     <label>Result:</label> <span id="result">&nbsp;</span>
63
    </div><div>
64

    
65
  </div>
66
</body>
67
</html>