You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[🌶️🌶️ - HTTP server with file system](./WebServer.Sample/WebServer.Sample.FileSystem/)
9
10
-[🌶️🌶️ - Dependency Injection](./WebServer.DI/)
10
11
11
12
## Usage
@@ -68,9 +69,10 @@ The `RouteAnyTest`is called whenever the url is `test/any` whatever the method i
68
69
69
70
There is a more advance example with simple REST API to get a list of Person and add a Person. Check it in the [sample](./WebServer.Sample/ControllerPerson.cs).
70
71
71
-
**Important**
72
-
* By default the routes are not case sensitive and the attribute **must** be lowercase
73
-
* If you want to use case sensitive routes like in the previous example, use the attribute `CaseSensitive`. As in the previous example, you **must** write the route as you want it to be responded to.
72
+
> ![Important]
73
+
>
74
+
> - By default the routes are not case sensitive and the attribute **must** be lowercase
75
+
> - If you want to use case sensitive routes like in the previous example, use the attribute `CaseSensitive`. As in the previous example, you **must** write the route as you want it to be responded to.
74
76
75
77
## A simple GPIO controller REST API
76
78
@@ -84,6 +86,7 @@ You will find in simple [GPIO controller sample](./WebServer.GpioRest) REST API.
84
86
- To read the pin 4: http://yoururl/read/4, you will get as a raw text `high`or `low`depending on the state
85
87
86
88
## DI integration with controllers
89
+
87
90
Check [WebServer.DI sample](./WebServer.DI) if you want to use controllers with automatically injecting services from [nanoFramework.DependencyInjection](https://github.com/nanoframework/nanoFramework.DependencyInjection).
88
91
89
92
- Type you credentials in Program.cs files
@@ -95,13 +98,13 @@ Check [WebServer.DI sample](./WebServer.DI) if you want to use controllers with
95
98
Controllers support authentication. 3 types of authentications are currently implemented on controllers only:
96
99
97
100
- Basic: the classic user and password following the HTTP standard. Usage:
98
-
-`[Authentication("Basic")]` will use the default credential of the webserver
99
-
-`[Authentication("Basic:myuser mypassword")]` will use myuser as a user and my password as a password. Note: the user cannot contains spaces.
101
+
-`[Authentication("Basic")]` will use the default credential of the webserver
102
+
-`[Authentication("Basic:myuser mypassword")]` will use myuser as a user and my password as a password. Note: the user cannot contains spaces.
100
103
- APiKey in header: add ApiKey in headers with the API key. Usage:
101
-
-`[Authentication("ApiKey")]` will use the default credential of the webserver
102
-
-`[Authentication("ApiKeyc:akey")]` will use akey as ApiKey.
104
+
-`[Authentication("ApiKey")]` will use the default credential of the webserver
105
+
-`[Authentication("ApiKeyc:akey")]` will use akey as ApiKey.
103
106
- None: no authentication required. Usage:
104
-
-`[Authentication("None")]` will use the default credential of the webserver
107
+
-`[Authentication("None")]` will use the default credential of the webserver
105
108
106
109
The Authentication attribute applies to both public Classes an public Methods.
107
110
@@ -166,16 +169,15 @@ using (WebServer server = new WebServer(80, HttpProtocol.Http, new Type[] { type
166
169
With the previous example the following happens:
167
170
168
171
- All the controller by default, even when nothing is specified will use the controller credentials. In our case, the Basic authentication with the default user (topuser) and password (topPassword) will be used.
169
-
- When calling http://yoururl/authbasic from a browser, you will be prompted for the user and password, use the default one topuser and topPassword to get access
170
-
- When calling http://yoururl/authnone, you won't be prompted because the authentication has been overridden for no authentication
171
-
- When calling http://yoururl/authbasicspecial, the user and password are different from the defautl ones, user2 and password is the right couple here
172
+
- When calling http://yoururl/authbasic from a browser, you will be prompted for the user and password, use the default one topuser and topPassword to get access
173
+
- When calling http://yoururl/authnone, you won't be prompted because the authentication has been overridden for no authentication
174
+
- When calling http://yoururl/authbasicspecial, the user and password are different from the defautl ones, user2 and password is the right couple here
172
175
- If you would have define in the controller a specific user and password like `[Authentication("Basic:myuser mypassword")]`, then the default one for all the controller would have been myuser and mypassword
173
176
- When calling http://yoururl/authapi, you must pass the header `ApiKey` (case sensitive) with the value `superKey1234` to get authorized, this is overridden the default Basic authentication
174
177
- When calling http://yoururl/authdefaultapi, the default key `ATopSecretAPIKey1234` will be used so you have to pass it in the headers of the request
175
178
176
179
All up, this is an example to show how to use authentication, it's been defined to allow flexibility.
177
180
178
-
179
181
## Managing incoming queries thru events
180
182
181
183
Very basic usage is the following:
@@ -225,15 +227,27 @@ if (url.ToLower().IndexOf("/param.htm") == 0)
225
227
}
226
228
```
227
229
228
-
And server static files:
230
+
To serve static files, you have to use the `nanoFramework.WebServer.FileSystem` nuget. This is only supported on devices having the `System.IO.FileSystem` capability.
229
231
230
232
```csharp
231
-
varfiles=storage.GetFiles();
232
-
foreach (varfileinfiles)
233
+
// Gets the list of all files in a specific directory
234
+
// See the MountExample for more details if you need to mount an SD card and adjust here
0 commit comments