forked from typicode/jsonplaceholder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
193 lines (159 loc) · 6.77 KB
/
index.html
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSONPlaceholder - Fake online REST API for developers</title>
<meta name="description" content="Fake online REST API for developers">
<meta name="author" content="Typicode">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/mono-blue.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<link rel="stylesheet" type="text/css" href="style.css">
<!-- Google plus -->
<script src="https://apis.google.com/js/platform.js" async defer></script>
</head>
<body>
<header>
<h1><img src="http://i.imgur.com/QRlAg0b.png"><br>JSONPlaceholder </h1>
<p>
Fake Online REST API for Testing and Prototyping<br>
<small>powered by <a href="https://github.com/typicode/json-server">JSON Server</a></small>
</p>
</header>
<div class="narrow">
<div class="center">
<!-- Twitter button -->
<div class="inline">
<a href="https://twitter.com/share" class="twitter-share-button" data-dnt="true">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
</div>
<!-- Google plus -->
<div class="inline">
<div class="g-plusone" data-size="medium"></div>
</div>
<!-- Facebook -->
<div class="inline">
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.0";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like" data-href="http://jsonplaceholder.typicode.com/" data-layout="button_count" data-action="recommend" data-show-faces="false" data-share="false"></div>
</div>
</div>
<h2>Intro</h2>
<p>
JSONPlaceholder is a free online REST service that you can use whenever you need some fake data.
</p>
<p>
It's great for tutorials, faking a server, sharing code examples, ...
</p>
<h2>Example</h2>
<p>Run this code in a console or from anywhere (CORS and JSONP supported).</p>
<pre><code class="javascript">var root = 'http://jsonplaceholder.typicode.com';
$.ajax({
url: root + '/posts/1',
method: 'GET'
}).then(function(data) {
console.log(data);
});</code></pre>
<p>
<button id="run">Run</button>
</p>
<p id="result" class="json">"Try me!"</p>
<h2>Resources</h2>
<p>
Inspired by common use cases.
</p>
<table>
<tr><td><a href="/posts">/posts</a><td><td>100 items</td></tr>
<tr><td><a href="/comments">/comments</a><td><td>500 items</td></tr>
<tr><td><a href="/albums">/albums</a><td><td>100 items</td></tr>
<tr><td><a href="/photos">/photos</a><td><td>200 items</td></tr>
<tr><td><a href="/todos">/todos</a><td><td>200 items</td></tr>
<tr><td><a href="/users">/users</a><td><td>10 items</td></tr>
</table>
<h2>Routes</h2>
<p>
All HTTP verbs are supported.
</p>
<table>
<tr><td class="verb">GET</td><td><a href="/posts">/posts</a></td></tr>
<tr><td class="verb">GET</td><td><a href="/posts/1">/posts/1</a></td></tr>
<tr><td class="verb">GET</td><td><a href="/posts/1/comments">/posts/1/comments</a></td></tr>
<tr><td class="verb">GET</td><td><a href="/comments?postId=1">/comments?postId=1</a></td></tr>
<tr><td class="verb">GET</td><td><a href="/posts?userId=1">/posts?userId=1</a></td></tr>
<tr><td class="verb">POST</td><td>/posts</td></tr>
<tr><td class="verb">PUT</td><td>/posts/1</td></tr>
<tr><td class="verb">PATCH</td><td>/posts/1</td></tr>
<tr><td class="verb">DELETE</td><td>/posts/1</td></tr>
</tr>
</table>
<p>
View usage <a href="https://github.com/typicode/jsonplaceholder#how-to">examples</a>.
</p>
<h2>Use your OWN data</h2>
<p>
<a href="https://github.com/typicode/json-server">JSON Server</a> powers this website.
You can use it to create a <strong>fake API</strong> in seconds with <strong>zero coding</strong>.
</p>
<pre>
<code class="bash">$ npm install -g json-server</code>
</pre>
<p id="os-x">
Hey, you seem to be on OS X. Check also <a href="https://github.com/typicode/katon">katon</a>,
a development tool I've built.
</p>
</div>
<footer>
<p>
Coded and built with heart by <a href="https://github.com/typicode">Typicode</a>.
Source code available on <a href="https://github.com/typicode/jsonplaceholder">GitHub</a>.
</p>
</footer>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-44497010-1', 'typicode.com');
ga('send', 'pageview');
</script>
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script>
// Highlight result element
$('#result').each(function(i, block) {
hljs.highlightBlock(block);
});
// Run example
$('#run').click(function() {
var root = 'http://jsonplaceholder.typicode.com';
$.ajax({
url: root + '/posts/1',
method: 'GET'
}).then(function(data) {
var str = JSON.stringify(data, null, '\t')
$('#result').html(
str.replace(/\n/g, '<br/>')
.replace(/\\n/g, ' ')
.replace(/\t/g, ' ')
);
$('#result').each(function(i, block) {
hljs.highlightBlock(block);
});
});
});
// Display os-x element only for OS X users
var isMac = navigator.platform.toLowerCase().indexOf('mac') >= 0;
if (isMac) {
document.getElementById('os-x').style.display = 'block'
}
// Tell that jQuery can be used in console
console.log('You can use jQuery functions')
</script>
</body>
</html>