Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciussanchez authored Dec 28, 2021
1 parent 63328d2 commit e85da9d
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ This middleware is compatible with projects developed in:
- [X] Delphi
- [X] Lazarus

## ⚡️ Quickstart
## ⚡️ Quickstart Delphi
```delphi
uses
Horse,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e85da9d

Please sign in to comment.