forked from pfrazee/stdrel.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrel.php
115 lines (105 loc) · 4.1 KB
/
rel.php
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
<?
require('inc/index.php');
use com\stdrel as host;
host\links\setheader('rel');
?>
<!doctype html>
<html>
<head>
<title>stdrel.com/rel - Relation Type</title>
<?= partials\styles() ?>
<?= partials\syntaxhighlighter() ?>
<?= partials\bootstrapjs() ?>
</head>
<body>
<div id="footer-wrapper-helper">
<?= host\partials\header('rel') ?>
<?= host\partials\reltypes_nav('rel') ?>
<div id="reltype" class="stdpage">
<div class="content">
<h2>stdrel.com/rel <small>Relation Type</small></h2>
<p>The resource is a relation type.</p>
<p><b class="glyphicon glyphicon-flag text-danger"></b> Resources which export this type <strong>SHOULD</strong>:</p>
<ul>
<li>Support the <code>GET</code> method with Accept of <code>text/plain</code> and/or <code>text/html</code>, responding with documentation for the reltype's semantics and behaviors.</li>
</ul>
<br><br>
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title">Reference implementation</h3></div>
<div class="panel-body">
<ul class="nav nav-tabs">
<li class="active"><a href="#express" data-toggle="tab">Node + Express</a></li>
<li><a href="#local" data-toggle="tab">Local</a></li>
<li><a href="#servware" data-toggle="tab">Local + Servware</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="express">
<p>Written with <a href="http://nodejs.org/">Node.js</a> and <a href="http://expressjs.com/">Express</a></p>
<pre><code class="language-javascript">var express = require('express');
var app = express();
app.all('/', function(req, res, next) {
// Set headers
res.set('Link', '</>; rel="self stdrel.com/rel"; title="My Reltype"');
res.set('Content-Type', 'text/html');
next();
});
app.head('/', function(req, res) {
// Respond with headers only
res.send(204);
});
app.get('/', function(req, res){
// Respond with HTML
res.html('<h1>My Reltype Spec</h1>');
});
app.listen(3000);</code></pre>
</div>
<div class="tab-pane" id="local">
<p>Written with <a href="http://httplocal.com">Local.js</a></p>
<pre><code class="language-javascript">importScripts('/local.js');
function main(req, res) {
// Set headers
res.header('Link', [{ href: '/', rel: 'self stdrel.com/rel', title: 'My Reltype' }]);
res.header('Content-Type', 'text/html');
if (req.method == 'HEAD') {
// Respond with headers only
res.writeHead(204, 'OK, no content').end();
return;
}
if (req.method == 'GET') {
// Respond with HTML
res.writeHead(200, 'OK').end('<h1>My Reltype Spec</h1>')
return;
}
// Invalid method
res.writeHead(405, 'Bad Method').end();
}</code></pre>
</div>
<div class="tab-pane" id="servware">
<p>Written with <a href="https://github.com/pfraze/servware">Servware</a>, full definition</p>
<pre><code class="language-javascript">importScripts('/local.js');
importScripts('/servware.js');
var main = servware();
main.route('/')
.link({ href: '/', rel: 'self stdrel.com/rel', title: 'My Reltype' })
.method('GET', function(req) {
req.assert({ accept: 'text/html' });
return [200, '<h1>My Reltype Spec</h1>', {'Content-Type': 'text/html'}];
});</code></pre>
<p>Using protocols</p>
<pre><code class="language-javascript">importScripts('/local.js');
importScripts('/servware.js');
var main = servware();
main.route('/')
.link({ href: '/', rel: 'self', title: 'My Reltype' })
.protocol('stdrel.com/rel', {
html: '<h1>My Reltype Spec</h1>'
});</code></pre>
</div>
</div>
</div>
</div>
<div id="footer-wrapper-push"></div>
</div>
<?= host\partials\footer() ?>
</body>
</html>