Skip to content
This repository was archived by the owner on Jul 17, 2024. It is now read-only.

Commit 6ce9ebe

Browse files
committed
Improved README.md
1 parent 2ad29ed commit 6ce9ebe

File tree

1 file changed

+88
-18
lines changed

1 file changed

+88
-18
lines changed

README.md

Lines changed: 88 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@ You don't need Coffeescript for it to function.
88
---
99

1010
#### Features:
11-
+ Authorization (optional bcrypt)
12-
+ CORS
11+
+ Authorization (optional bcrypt, anonymous)
12+
+ CORS (Cross-Origin Resource Sharing)
1313
+ HTTP/S (TLS)
14-
+ BodyParser
15-
+ AcceptParser
16-
+ DateParser
17-
+ QueryParser
14+
+ Body Parser
15+
+ Accept Parser
16+
+ Date Parser
17+
+ Query Parser
1818
+ Jsonp
19-
+ GzipResponse
19+
+ Gzip Response / Compression
2020
+ Throttle
21-
+ ConditionalRequest
22-
+ Extensive routing
21+
+ Conditional Request
22+
+ Extensive Routing
2323
+ Logging (morgan/custom)
2424
+ Plugins (extend your api)
2525
+ Addons (extend sys-api' core)
2626

2727
---
2828

2929
### Routing
30-
There are tons of routing-variations!
30+
You can use a route in many different ways!
3131

3232
For example, this is how simple it can be:
3333

@@ -49,7 +49,7 @@ api.get('/hello', (router) ->
4949
#=> "Hello World"
5050
```
5151

52-
OR use an object:
52+
You can also use an object:
5353

5454
```coffeescript
5555
api.get({ url: '/hello' }, "Hello World")
@@ -63,11 +63,17 @@ Check the wiki for more: https://github.com/Burnett01/sys-api/wiki/Routing
6363
### Authorization
6464
Such as Restify, currently only HTTP Basic Auth and HTTP Signature are supported.
6565

66+
In addition, we allow bcyrpt encrypted passwords to be used in Basic Auth HTTP header,
67+
and anonymous access.
68+
69+
#### Basic example:
70+
6671
```coffeescript
6772
api.auth({
6873
enabled: true,
69-
method: 'basic',
74+
method: 'basic',
7075
bcrypt: false,
76+
anon: false,
7177
users: {
7278
testuser: {
7379
password: 'testpw'
@@ -76,7 +82,71 @@ api.auth({
7682
})
7783
```
7884

79-
> if bcrypt is enabled, pass an encrypted hash with your route.
85+
#### Bcrypt example:
86+
87+
> if bcrypt is enabled, pass the hash with the Basic Auth header.
88+
89+
90+
```coffeescript
91+
api.auth({
92+
enabled: true,
93+
method: 'basic',
94+
bcrypt: true,
95+
anon: false,
96+
users: {
97+
testuser: {
98+
# Whenever bcrypt is enabled, we must use the hash instead of the plain password.
99+
#
100+
# For example:
101+
# Let's say the plain password "testpw" becomes this bcrypt hash:
102+
# "$2a$04$GRD1gvo20Gqskwk5g9qsgO0urOWDAO[...]"
103+
# ---------------------------------------------------------------------
104+
# So we must use the hash:
105+
password: '$2a$04$GRD1gvo20Gqskwk5g9qsgO0ur[...]'
106+
# ---------------------------------------------------------------------
107+
# Now our application (for instance PHP) generates a new hash
108+
# to be used in authorization procedure.
109+
# As soon as the application wants to perform authorization against the API,
110+
# the Basic Auth header must contain the hash in its base64 representation:
111+
# ---------------------------------------------------------------------
112+
# This is how a generic authorization header looks like:
113+
# username:password
114+
# -> test:testpw
115+
# -> base64
116+
# -> dGVzdDp0ZXN0cHc=
117+
# ++ So the Authorization header becomes:
118+
# Authorization: Basic dGVzdDp0ZXN0cHc=
119+
# ---------------------------------------------------------------------
120+
# This is how a the authorization header with bcrypt may look like:
121+
# username:hash
122+
# -> test:$2a$04$jdGtS8OCXCn.e2b1DI584OAA65r0[...]
123+
# -> base64
124+
# -> dGVzdDokMmEkMDQkamRHdFM4T0NYQ24uZTJiMURJNTg0T0FBNjV[...]
125+
# ++ So the Authorization header becomes:
126+
# Authorization: Basic dGVzdDokMmEkMDQkamRHdFM4T0NYQ24uZTJiMURJNTg0T0FBNjV[...]
127+
}
128+
}
129+
})
130+
```
131+
132+
#### Anonymous access:
133+
You may also allow anonymous access by using the ``anon`` property.
134+
135+
If anonymous access is enabled, valid and anonymous users have access.
136+
137+
```coffeescript
138+
api.auth({
139+
enabled: true,
140+
method: 'basic',
141+
bcrypt: false,
142+
anon: true,
143+
users: {
144+
testuser: {
145+
password: 'testpw'
146+
}
147+
}
148+
})
149+
```
80150

81151
---
82152

@@ -97,9 +167,9 @@ api.cors({
97167
### HTTP/S
98168
Sys-API supports HTTP and HTTPS simultaneously.
99169

100-
You don't have to set up things twice. Simply pass a key and certificate property,
170+
You don't have to define things twice. Simply pass a key and certificate property,
101171
and the API will handle that for you. Once configured, your API-instance will listen on your specified HTTP and HTTPS port.
102-
Port 443 is the default port for HTTPS. If you wish to use any other port, simply pass a second argument to ```connect()```.
172+
Port 443 is the default port for HTTPS. If you wish to use any other port, simply pass a second argument to ```listen()```.
103173

104174
```coffeescript
105175
api = new API({
@@ -109,14 +179,14 @@ api = new API({
109179
}
110180
})
111181

112-
api.connect(80) #API is going to listen on HTTP(80) and HTTPS(443)
182+
api.listen(80) #API is going to listen on HTTP(80) and HTTPS(443)
113183

114184
# OR
115185

116-
api.connect(80, 8443) #API is going to listen on HTTP(80) and HTTPS(8443)
186+
api.listen(80, 8443) #API is going to listen on port HTTP(80) and HTTPS(8443)
117187
```
118188

119-
> If no key/certificate property is available, your API-instance won't listen to HTTPS.
189+
> If no key/certificate property is available, your API-instance won't support HTTPS.
120190
121191
---
122192

0 commit comments

Comments
 (0)