-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
396de38
commit 5cd444e
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,29 @@ | ||
# QuickMan.Lib | ||
### Quick way to build self-hosted APIs | ||
|
||
Example: | ||
```C# | ||
private QuickMan API; | ||
public void Run() | ||
{ | ||
API = new QuickMan(); | ||
var Endpoints = new Dictionary<string, Action<HttpListenerContext>>(); | ||
|
||
// Endpoint should not start with a '/' | ||
// i.e Endpoints.Add("/HelloWorld", HelloWorld); won't work | ||
// To add an endpoint: Endpoints.Add("EndpointName", EndpointMethod); | ||
Endpoints.Add("HelloWorld", HelloWorld); | ||
|
||
// Server now will start on http://localhost:1999/ | ||
API.Start(Endpoints, 20 /*Maximum Simultaneous Connections*/); | ||
} | ||
|
||
// http://localhost:1999/HelloWorld | ||
public void HelloWorld(HttpListenerContext Context) | ||
{ | ||
// You always have a respond to the request ASAP, | ||
// otherwise client will drop the connection after ~30 Seconds | ||
API.Respond("Hello World!", Context); | ||
Console.WriteLine($"Said 'Hello World!' to {Context.Request.UserHostAddress}"); | ||
} | ||
``` |