-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
201 lines (172 loc) · 7.27 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
194
195
196
197
198
199
200
201
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="browser-ie7 lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="browser-ie8 lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="browser-ie9 lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="browser-modern"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/css/tachyons.min.css">
<meta name="theme-color" content="#98a2d2">
<meta name="og:site_name" content="servies">
<meta name="og:title" content="servies">
<meta name="og:description" content="servies is a micro framework written in bash.">
<meta name="description" content="servies is a micro framework written in bash.">
<meta name="referrer" content="origin">
<style>
@import url("https://fonts.googleapis.com/css?family=Spectral");
.spectral {
font-family: Spectral,serif;
}
h1 {
font-weight: 100;
}
body {
background: white;
cursor: default;
font-weight: 100;
}
pre,
code {
font-family: monospace;
font-weight: bold;
word-break: break-word;
}
pre {
color: #383838;
padding: 0;
margin: 2rem 0;
overflow: auto;
}
@media screen and (min-width:45em) {
pre {
overflow: visible;
}
}
pre cstr {
color: rgb(101, 139, 255);
}
pre cnum {
color: #3b3bff;
}
code {
background: rgba(152, 162, 210, 0.15);
padding: 0 3px;
color: black;
font-weight: 100;
}
.servieslogo {
width: 10rem;
margin: 1rem;
}
.container {
max-width: 50rem;
padding-left: 1rem;
padding-right: 1rem;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="container center pt3 lh-copy baskerville f4">
<div class="tc">
<img class="servieslogo" src="servieslogo.png" alt="servies logo" />
</div>
<p>
<code>servies</code> is a micro framework written in bash. It uses
<code>netcat</code> to listen for and serve HTTP requests. Defining
request handlers is simply done by running a function with the same
name as the HTTP method, and passing it a url and command to execute.
For example, here's how you would create a new "/greet/" endpoint
that you could pass a name to and use in your response:
</p>
<pre>get <cstr>"/greet/:name"</cstr> echo <cstr>'hi $name, how are you??'</cstr></pre>
<p>
As you can see, you can add path variables to your urls using syntax
that you might find familiar. Any word that starts with a
<code>:</code> will be treated as a path variable which is then
available to you in the command.
</p>
<h1>Documentation</h1>
<p>
You have full control over the details of your response body.
Anything sent to <code>stdout</code> by your handler function or
command will be sent back as the response body. By default, your
response will be sent back as a <code>200 OK</code>
<code>plain/text</code> response, but there's also a status and a
header command that you can use to customize the status code and to
add any header you want:
</p>
<pre>get <cstr>"/authenticated/:name"</cstr> authenticate_then_get_data
authenticate_then_get_data() {
header <cstr>"Content-Type"</cstr> <cstr>"application/json"</cstr>
if [ <cstr>"$name"</cstr> = <cstr>"marcos"</cstr> ]; then
status <cnum>200</cnum> <cstr>"OK"</cstr>
echo <cstr>"{\"number\": 7}"</cstr>
else
status <cnum>403</cnum> <cstr>"Forbidden"</cstr>
echo <cstr>"{\"error\": \"invalid name!\"}"</cstr>
fi
}</pre>
<p>
You get the following HTTP commands: <code>get</code>,
<code>post</code>, <code>put</code>, and <code>patch</code>. All of
which have this signature: <code>name (name: string, ...cmd:
string)</code>. Along with that there is <code>status</code> and
<code>header</code>, and <code>not_found</code> which is called when
no routes match an incoming request. This method can be overwritten
by you.
</p>
<h1>Getting started</h1>
<p>
Getting started is easy. First, make sure you have a newer version of
bash install. This may mean using Linux. So first get Linux. Second,
<a href="https://github.com/minond/servies/archive/master.zip" class="link">download</a>
and extract the code. Next run <code>make dependencies</code> to
download external libraries we depend on. You can run <code>make
install</code> to make the <code>servies</code> command available
from anywhere, but this is not required. Once this is done you can
run <code>./servies sample.sh</code> to start the sample web app or
pass in your own source file to run your own app.
</p>
<h1>Contributing</h1>
<p>
All help is appreciated. And even though this is a joke project there
are still some very valuable lessons to learn here about bash as a
language and projects in a language with a few restrictions. To
contribute, first make sure you've done everything in the "Getting
started" section and run <code>make lint test</code> before pushing
your code. Unit tests are written using
<a class="link" href="https://github.com/minond/expect">expect</a>
and
<a class="link" href="https://github.com/koalaman/shellcheck">shellcheck</a>
is the static analyser.
</p>
<div class="mt4">
<a target="_blank" class="link" href="https://travis-ci.org/minond/servies">
<img src="https://travis-ci.org/minond/servies.svg?branch=master" />
</a>
<a target="_blank" class="link pl1" href="https://github.com/minond/servies">
<img src="https://img.shields.io/badge/code-minond%2Fservies-brightgreen.svg" />
</a>
</div>
</div>
<footer class="bt b--light-gray spectral mt4 pv1">
<div class="container">
<p class="lh-copy w-60-ns">
~ <a href="/" class="link red dim">Marcos Minond</a>
</p>
</div>
</footer>
</body>
<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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-102424562-1', 'auto');
ga('send', 'pageview');
</script>
</html>