From e85da9d9528484117ce32814d827e50d7c94a308 Mon Sep 17 00:00:00 2001 From: Vinicius Sanchez Date: Mon, 27 Dec 2021 21:31:27 -0300 Subject: [PATCH] Update README.md --- README.md | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7b5cd55..ac49a7d 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ This middleware is compatible with projects developed in: - [X] Delphi - [X] Lazarus -## ⚡️ Quickstart +## ⚡️ Quickstart Delphi ```delphi uses Horse, @@ -53,6 +53,46 @@ begin end; ``` +## ⚡️ Quickstart Lazarus +```delphi +{$MODE DELPHI}{$H+} + +uses + {$IFDEF UNIX}{$IFDEF UseCThreads} + cthreads, + {$ENDIF}{$ENDIF} + Horse, + Horse.BasicAuthentication, // It's necessary to use the unit + SysUtils; + +procedure GetPing(Req: THorseRequest; Res: THorseResponse; Next: TNextProc); +begin + Res.Send('Pong'); +end; + +function DoLogin(const AUsername, APassword: string): Boolean; +begin + // Here inside you can access your database and validate if username and password are valid + Result := AUsername.Equals('user') and APassword.Equals('password'); +end; + +begin + // It's necessary to add the middleware in the Horse: + THorse.Use(HorseBasicAuthentication(DoLogin)); + + // The default header for receiving credentials is "Authorization". + // You can change, if necessary: + // THorse.Use(HorseBasicAuthentication(MyCallbackValidation, THorseBasicAuthenticationConfig.New.Header('X-My-Header-Authorization'))); + + // You can also ignore routes: + // THorse.Use(HorseBasicAuthentication(MyCallbackValidation, THorseBasicAuthenticationConfig.New.SkipRoutes(['/ping']))); + + THorse.Get('/ping', GetPing); + + THorse.Listen(9000); +end. +``` + ## 📌 Status Code This middleware can return the following status code: * [401](https://httpstatuses.com/401) - Unauthorized