Getting Started
Build your first SimpleW HTTP endpoint and see it running in just a few minutes.
What you will build
A small HTTP server listening on localhost:2015 with one endpoint that returns a JSON response.
Before you start
You need the .NET 8 SDK or later and a terminal. The commands below work on Windows, macOS and Linux.
You can check the SDK installed on your machine with:
dotnet --version1. Create the project
Start with a regular .NET console application. SimpleW does not require a special host or project type.
mkdir hello-simplew
cd hello-simplew
dotnet new console
dotnet add package SimpleWYour project is ready. There is no additional dependency or configuration file to install.
2. Write your first server
Replace the content of Program.cs with the following code:
using System.Net;
using SimpleW;
using SimpleW.Observability;
Log.SetSink(Log.ConsoleWriteLine);
var server = new SimpleWServer(IPAddress.Loopback, 2015);
server.MapGet("/api/hello", static () => {
return new { message = "Hello from SimpleW!" };
});
await server.RunAsync();2
3
4
5
6
7
8
9
10
11
12
13
This is a complete SimpleW application: one server, one route and one call that keeps it running.
3. Start SimpleW
Run the application from the project directory:
dotnet runYou should see output similar to the terminal below. Timestamps will naturally be different on your machine.
The process stays active while SimpleW is listening. Leave this terminal open for the next step.
4. Make your first request
Open a second terminal and call the endpoint:
Invoke-RestMethod http://localhost:2015/api/hellocurl http://localhost:2015/api/helloOr open http://localhost:2015/api/hello directly in your browser.
SimpleW serializes the returned object as JSON:
{
"message": "Hello from SimpleW!"
}You have just created and served your first SimpleW endpoint.
5. Understand the code
| Code | What it does |
|---|---|
Log.SetSink(...) | Sends SimpleW lifecycle messages to the console. |
SimpleWServer(...) | Creates a server bound locally to port 2015. |
MapGet(...) | Maps GET /api/hello to a C# delegate. |
RunAsync() | Starts listening and waits until the application is stopped. |
Press Ctrl + C in the first terminal when you want to stop the server.
Prefer to start from a template?
SimpleW also provides project templates. See the Templates addon when you want to skip the manual project setup.
Where to go next
Choose the path that matches what you want to build.