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 (and its dependencies) in your project.

Usage

For detailed explanation You can also see docs

// Program.cs
using SAPI;
using SAPI.Endpoints;
using Project.Endpoints;

public static void Main(string[] args)
{
    // Init SAPI
    Server sapi = new();
    sapi.Start();
}
// Endpoints/Ping.cs
using System.Net;
using SAPI;

namespace Project.Endpoints
{
    public class Ping : Endpoint
    {
        public override string url { get; } = "ping";

        private override void Get(ref Packet packet)
        {
            Console.WriteLine("Ping!");
            
            Error.Page(HttpStatus.EnhanceYourCalm, ref packet);
        }
    }
}