Skip to content

Maciejowski2006/SAPI

Repository files navigation

SAPI - Simple API

Nuget NuGet GitHub

SAPI is a library for creating APIs with C#. It's simple by design and allows for a lot of flexibility.

Installation

Add as dependency in NuGet

Install-Package SAPI -ProjectName <project>

In your preferred IDE: SAPI in rider's NuGet PM

By downloading and referencing the DLL in your project.

Usage

For detailed explanation You can also see wiki

// Program.cs using SAPI; using SAPI.Endpoints; using Project.Endpoints; public static void Main(string[] args) { // Init SAPI Server sapi = new(); // Mount endpoints(routes) sapi.MountEndpoint(new Ping()); // Start SAPI sapi.Start(); }
// Endpoints/Ping.cs using System.Net; using SAPI.Endpoints; using SAPI.Utilities; namespace Project.Endpoints { public class Ping : IEndpoint { public string url { get; } = "ping"; public Method method { get; } = Method.GET; public override void Task(ref HttpListenerRequest request, ref HttpListenerResponse response, Dictionary<string, string> parameters) { Console.WriteLine("Ping!"); Utilities.HtmlResponse("Pong!", ref response); } } }