forked from pfrazee/stdrel.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmedia.php
122 lines (111 loc) · 4.51 KB
/
media.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
116
117
118
119
120
121
122
<?
require('inc/index.php');
use com\stdrel as host;
host\links\setheader('media');
?>
<!doctype html>
<html>
<head>
<title>/media - Media</title>
<?= partials\styles() ?>
<?= partials\syntaxhighlighter() ?>
<?= partials\bootstrapjs() ?>
</head>
<body>
<div id="footer-wrapper-helper">
<?= host\partials\header('media') ?>
<?= host\partials\reltypes_nav('media') ?>
<div id="reltype" class="stdpage">
<div class="content">
<h2>stdrel.com/media <small>Media</small></h2>
<p>The resource is an image, video, audio, or text document.</p>
<p><b class="glyphicon glyphicon-flag text-danger"></b> Links which export this type <strong>MUST</strong>:</p>
<ul>
<li>Include a `type` attribute labeling the mimetype of the content.</li>
</ul>
<p><b class="glyphicon glyphicon-flag text-danger"></b> Resources which export this type <strong>MUST</strong>:</p>
<ul>
<li>Support the <code>GET</code> method with Accept of the type given by the link <code>type</code>, responding with the media document.</li>
</ul>
<p>If the resource supports multiple types, it's recommended to use multiple links which each label the supported type.</p>
<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/media"; type="text/html"; title="Hello, World"');
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>Hello World</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/media', type: 'text/html', title: 'Hello, World' }]);
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>Hello World</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/media', type: 'text/html', title: 'Hello, World' })
.method('GET', function(req) {
req.assert({ accept: 'text/html' });
return [200, '<h1>Hello World</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: 'Hello, World' })
.protocol('stdrel.com/media', {
type: 'text/html',
content: '<h1>Hello World</h1>'
});</code></pre>
</div>
</div>
</div>
</div>
<div id="footer-wrapper-push"></div>
</div>
<?= host\partials\footer() ?>
</body>
</html>