Skip to content

Commit e85da9d

Browse files
Update README.md
1 parent 63328d2 commit e85da9d

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This middleware is compatible with projects developed in:
2020
- [X] Delphi
2121
- [X] Lazarus
2222

23-
## ⚡️ Quickstart
23+
## ⚡️ Quickstart Delphi
2424
```delphi
2525
uses
2626
Horse,
@@ -53,6 +53,46 @@ begin
5353
end;
5454
```
5555

56+
## ⚡️ Quickstart Lazarus
57+
```delphi
58+
{$MODE DELPHI}{$H+}
59+
60+
uses
61+
{$IFDEF UNIX}{$IFDEF UseCThreads}
62+
cthreads,
63+
{$ENDIF}{$ENDIF}
64+
Horse,
65+
Horse.BasicAuthentication, // It's necessary to use the unit
66+
SysUtils;
67+
68+
procedure GetPing(Req: THorseRequest; Res: THorseResponse; Next: TNextProc);
69+
begin
70+
Res.Send('Pong');
71+
end;
72+
73+
function DoLogin(const AUsername, APassword: string): Boolean;
74+
begin
75+
// Here inside you can access your database and validate if username and password are valid
76+
Result := AUsername.Equals('user') and APassword.Equals('password');
77+
end;
78+
79+
begin
80+
// It's necessary to add the middleware in the Horse:
81+
THorse.Use(HorseBasicAuthentication(DoLogin));
82+
83+
// The default header for receiving credentials is "Authorization".
84+
// You can change, if necessary:
85+
// THorse.Use(HorseBasicAuthentication(MyCallbackValidation, THorseBasicAuthenticationConfig.New.Header('X-My-Header-Authorization')));
86+
87+
// You can also ignore routes:
88+
// THorse.Use(HorseBasicAuthentication(MyCallbackValidation, THorseBasicAuthenticationConfig.New.SkipRoutes(['/ping'])));
89+
90+
THorse.Get('/ping', GetPing);
91+
92+
THorse.Listen(9000);
93+
end.
94+
```
95+
5696
## 📌 Status Code
5797
This middleware can return the following status code:
5898
* [401](https://httpstatuses.com/401) - Unauthorized

0 commit comments

Comments
 (0)