Skip to content

Commit 5d31be0

Browse files
authored
Update readme (#235)
* Update README.md * Update README.md
1 parent c0e5aa4 commit 5d31be0

File tree

1 file changed

+50
-17
lines changed

1 file changed

+50
-17
lines changed

README.md

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@
1717
- [EmbedIO 2.0 - What's new](#embedio-20---whats-new)
1818
- [Some usage scenarios](#some-usage-scenarios)
1919
- [Installation](#installation)
20+
- [Usage](#usage)
21+
- [WebServer Setup](#webserver-setup)
22+
- [IHttpContext Extension Methods](#ihttpcontext-extension-methods)
23+
- [Easy Routes](#easy-routes)
24+
- [Support for SSL](#support-for-ssl)
2025
- [Examples](#examples)
2126
- [Basic Example](#basic-example)
2227
- [Fluent Example](#fluent-example)
2328
- [REST API Example](#rest-api-example)
2429
- [WebSockets Example](#websockets-example)
25-
- [Support for SSL](#support-for-ssl)
2630
- [Related Projects and Nugets](#related-projects-and-nugets)
2731
- [Special Thanks](#special-thanks)
2832

@@ -94,6 +98,51 @@ PM> Install-Package EmbedIO
9498
> dotnet add package EmbedIO
9599
```
96100

101+
## Usage
102+
103+
### WebServer Setup
104+
105+
### IHttpContext Extension Methods
106+
107+
By adding the namespace `Unosquare.Labs.EmbedIO` to your class, you can use some helpful extension methods for `IHttpContext`, `IHttpResponse` and `IHttpRequest`. Those can be used in any Web module (like [Fallback Module](https://unosquare.github.io/embedio/api/Unosquare.Labs.EmbedIO.Modules.FallbackModule.html)) or inside a [WebAPI Controller](https://unosquare.github.io/embedio/api/Unosquare.Labs.EmbedIO.Modules.WebApiController.html) method.
108+
109+
Below, some common scenarios using a WebAPI Controller method as body function:
110+
111+
#### Writing a binary stream
112+
113+
For writing a binary stream directly to the Response Output Stream you can use [BinaryResponseAsync](https://unosquare.github.io/embedio/api/Unosquare.Labs.EmbedIO.Extensions.html#Unosquare_Labs_EmbedIO_Extensions_BinaryResponseAsync_Unosquare_Labs_EmbedIO_IHttpResponse_System_IO_Stream_System_Threading_CancellationToken_System_Boolean_). This method has an overload to use `IHttpContext` and you need to set the Content-Type beforehand.
114+
115+
```csharp
116+
[WebApiHandler(HttpVerbs.Get, "/api/binary")]
117+
public async Task<bool> GetBinary()
118+
{
119+
var stream = new MemoryStream();
120+
121+
// Call a fictional external source
122+
await GetExternalStream(stream);
123+
124+
return await this.BinaryResponseAsync(stream);
125+
}
126+
```
127+
128+
### Easy Routes
129+
130+
## Support for SSL
131+
132+
Both HTTP listeners (Microsoft and Unosquare) can open a web server using SSL. This support is for Windows only (for now) and you need to manually register your certificate or use the `WebServerOptions` class to initialize a new `WebServer` instance. This section will provide some examples of how to use SSL but first a brief explanation of how SSL works on Windows.
133+
134+
For Windows Vista or better, Microsoft provides Network Shell (`netsh`). This command line tool allows to map an IP-port to a certificate, so incoming HTTP request can upgrade the connection to a secure stream using the provided certificate. EmbedIO can read or register certificates to a default store (My/LocalMachine) and use them against a netsh `sslcert` for binding the first `https` prefix registered.
135+
136+
For Windows XP and Mono, you can use manually the `httpcfg` for registering the binding.
137+
138+
### Using a PFX file and AutoRegister option
139+
140+
The more practical case to use EmbedIO with SSL is the `AutoRegister` option. You need to create a `WebServerOptions` instance with the path to a PFX file and the `AutoRegister` flag on. This options will try to get or register the certificate to the default certificate store. Then it will use the certificate thumbprint to register with `netsh` the FIRST `https` prefix registered on the options.
141+
142+
### Using AutoLoad option
143+
144+
If you already have a certificate on the default certificate store and the binding is also registered in `netsh`, you can use `Autoload` flag and optionally provide a certificate thumbprint. If the certificate thumbprint is not provided, EmbedIO will read the data from `netsh`. After getting successfully the certificate from the store, the raw data is passed to the WebServer.
145+
97146
## Examples
98147

99148
### Basic Example
@@ -364,22 +413,6 @@ public class WebSocketsChatServer : WebSocketsServer
364413
}
365414
```
366415

367-
### Support for SSL
368-
369-
Both HTTP listeners (Microsoft and Unosquare) can open a web server using SSL. This support is for Windows only (for now) and you need to manually register your certificate or use the `WebServerOptions` class to initialize a new `WebServer` instance. This section will provide some examples of how to use SSL but first a brief explanation of how SSL works on Windows.
370-
371-
For Windows Vista or better, Microsoft provides Network Shell (`netsh`). This command line tool allows to map an IP-port to a certificate, so incoming HTTP request can upgrade the connection to a secure stream using the provided certificate. EmbedIO can read or register certificates to a default store (My/LocalMachine) and use them against a netsh `sslcert` for binding the first `https` prefix registered.
372-
373-
For Windows XP and Mono, you can use manually the httpcfg for registering the binding.
374-
375-
#### Using a PFX file and AutoRegister option
376-
377-
The more practical case to use EmbedIO with SSL is the `AutoRegister` option. You need to create a `WebServerOptions` instance with the path to a PFX file and the `AutoRegister` flag on. This options will try to get or register the certificate to the default certificate store. Then it will use the certificate thumbprint to register with `netsh` the FIRST `https` prefix registered on the options.
378-
379-
#### Using AutoLoad option
380-
381-
If you already have a certificate on the default certificate store and the binding is also registered in `netsh`, you can use `Autoload` flag and optionally provide a certificate thumbprint. If the certificate thumbprint is not provided, EmbedIO will read the data from `netsh`. After getting successfully the certificate from the store, the raw data is passed to the WebServer.
382-
383416
## Related Projects and Nugets
384417

385418
Name | Author | Description

0 commit comments

Comments
 (0)