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
This library was coded by [Laurent Ellerbach](@Ellerbach) who generously offered it to the .NET **nanoFramework** project.
18
+
This library was coded by [Laurent Ellerbach](https://github.com/Ellerbach) who generously offered it to the .NET **nanoFramework** project.
18
19
19
20
This is a simple nanoFramework WebServer. Features:
20
21
21
22
- Handle multi-thread requests
22
-
- Serve static files on any storage
23
+
- Serve static files from any storage using [`nanoFramework.WebServer.FileSystem` NuGet](https://www.nuget.org/packages/nanoFramework.WebServer.FileSystem). Requires a target device with support for storage (having `System.IO.FileSystem` capability).
23
24
- Handle parameter in URL
24
25
- Possible to have multiple WebServer running at the same time
25
26
- supports GET/PUT and any other word
@@ -31,6 +32,7 @@ This is a simple nanoFramework WebServer. Features:
- Does not support any zip in the request or response stream
35
37
36
38
## Usage
@@ -93,9 +95,10 @@ The `RouteAnyTest`is called whenever the url is `test/any` whatever the method i
93
95
94
96
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).
95
97
96
-
**Important**
97
-
* By default the routes are not case sensitive and the attribute **must** be lowercase
98
-
* 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.
98
+
> [!Important]
99
+
>
100
+
> By default the routes are not case sensitive and the attribute **must** be lowercase.
101
+
> 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.
99
102
100
103
## A simple GPIO controller REST API
101
104
@@ -113,13 +116,13 @@ You will find in simple [GPIO controller sample](https://github.com/nanoframewor
113
116
Controllers support authentication. 3 types of authentications are currently implemented on controllers only:
114
117
115
118
- Basic: the classic user and password following the HTTP standard. Usage:
116
-
-`[Authentication("Basic")]` will use the default credential of the webserver
117
-
-`[Authentication("Basic:myuser mypassword")]` will use myuser as a user and my password as a password. Note: the user cannot contains spaces.
119
+
-`[Authentication("Basic")]` will use the default credential of the webserver
120
+
-`[Authentication("Basic:myuser mypassword")]` will use myuser as a user and my password as a password. Note: the user cannot contains spaces.
118
121
- APiKey in header: add ApiKey in headers with the API key. Usage:
119
-
-`[Authentication("ApiKey")]` will use the default credential of the webserver
120
-
-`[Authentication("ApiKeyc:akey")]` will use akey as ApiKey.
122
+
-`[Authentication("ApiKey")]` will use the default credential of the webserver
123
+
-`[Authentication("ApiKeyc:akey")]` will use akey as ApiKey.
121
124
- None: no authentication required. Usage:
122
-
-`[Authentication("None")]` will use the default credential of the webserver
125
+
-`[Authentication("None")]` will use the default credential of the webserver
123
126
124
127
The Authentication attribute applies to both public Classes an public Methods.
125
128
@@ -184,9 +187,9 @@ using (WebServer server = new WebServer(80, HttpProtocol.Http, new Type[] { type
184
187
With the previous example the following happens:
185
188
186
189
- 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.
187
-
- 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
188
-
- When calling http://yoururl/authnone, you won't be prompted because the authentication has been overridden for no authentication
189
-
- When calling http://yoururl/authbasicspecial, the user and password are different from the defautl ones, user2 and password is the right couple here
190
+
- 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
191
+
- When calling http://yoururl/authnone, you won't be prompted because the authentication has been overridden for no authentication
192
+
- When calling http://yoururl/authbasicspecial, the user and password are different from the defautl ones, user2 and password is the right couple here
190
193
- 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
191
194
- 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
192
195
- When calling http://yoururl/authdefaultapi, the default key `ATopSecretAPIKey1234` will be used so you have to pass it in the headers of the request
@@ -246,19 +249,42 @@ if (url.ToLower().IndexOf("/param.htm") == 0)
246
249
And server static files:
247
250
248
251
```csharp
249
-
varfiles=storage.GetFiles();
250
-
foreach (varfileinfiles)
252
+
// E = USB storage
253
+
// D = SD Card
254
+
// I = Internal storage
255
+
// Adjust this based on your configuration
256
+
conststringDirectoryPath="I:\\";
257
+
string[] _listFiles;
258
+
259
+
// Gets the list of all files in a specific directory
260
+
// See the MountExample for more details if you need to mount an SD card and adjust here
releaseNotesInline: 'Check the [changelog]($(Build.Repository.Uri)/blob/$(Build.SourceBranchName)/CHANGELOG.md).<br><br><h4>Install from NuGet</h4><br>The following NuGet packages are available for download from this release:<br>:package: [nanoFramework.WebServer](https://www.nuget.org/packages/$(nugetPackageName)/$(MY_NUGET_VERSION)) v$(MY_NUGET_VERSION).<br>:package: [nanoFramework.WebServer.FileSystem (requires support of storage through System.IO.FileSystem)](https://www.nuget.org/packages/nanoFramework.WebServer.FileSystem/$(MY_NUGET_VERSION)) v$(MY_NUGET_VERSION)'
0 commit comments