Skip to content

Commit

Permalink
Added lazarus samples
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciussanchez committed Nov 5, 2020
1 parent c87a64d commit d31589d
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 1 deletion.
14 changes: 14 additions & 0 deletions samples/lazarus/boss-lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"hash": "d41d8cd98f00b204e9800998ecf8427e",
"updated": "2020-11-04T21:25:53.8317735-03:00",
"installedModules": {
"github.com/hashload/horse": {
"name": "horse",
"version": "v2.0.3",
"hash": "fb7144725ff788c49af1307f97f23b5a",
"artifacts": {},
"failed": false,
"changed": false
}
}
}
11 changes: 11 additions & 0 deletions samples/lazarus/boss.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "lazarus",
"description": "",
"version": "1.0.0",
"homepage": "",
"mainsrc": "./",
"projects": [],
"dependencies": {
"github.com/hashload/horse": "^v2.0.3"
}
}
63 changes: 63 additions & 0 deletions samples/lazarus/samples.lpi
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="My Application"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes Count="1">
<Item1 Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
<Modes Count="0"/>
</RunParams>
<Units Count="1">
<Unit0>
<Filename Value="samples.lpr"/>
<IsPartOfProject Value="True"/>
</Unit0>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="samples"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<OtherUnitFiles Value="modules\horse\src;..\..\src"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
</CompilerOptions>
<Debugging>
<Exceptions Count="4">
<Item1>
<Name Value="EAbort"/>
</Item1>
<Item2>
<Name Value="ECodetoolError"/>
</Item2>
<Item3>
<Name Value="EFOpenError"/>
</Item3>
<Item4>
<Name Value="EResNotFound"/>
</Item4>
</Exceptions>
</Debugging>
</CONFIG>
30 changes: 30 additions & 0 deletions samples/lazarus/samples.lpr
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
program samples;

{$MODE DELPHI}{$H+}

uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Horse, Horse.Jhonson, fpjson, SysUtils;

procedure PostPing(Req: THorseRequest; Res: THorseResponse; Next: TNextProc);
var
LBody: TJSONObject;
begin
LBody := Req.Body<TJSONObject>;
Res.Send<TJSONObject>(LBody);
end;

procedure OnListen(Horse: THorse);
begin
Writeln(Format('Server is runing on %s:%d', [Horse.Host, Horse.Port]));
end;

begin
THorse.Use(Jhonson);

THorse.Post('/ping', PostPing);

THorse.Listen(9000, OnListen);
end.
2 changes: 1 addition & 1 deletion src/Horse.Jhonson.pas
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ procedure Middleware(Req: THorseRequest; Res: THorseResponse; Next: {$IF DEFINED
if Assigned(LContent) and LContent.InheritsFrom({$IF DEFINED(FPC)}TJsonData{$ELSE}TJSONValue{$ENDIF}) then
begin
LWebResponse.Content := {$IF DEFINED(FPC)}TJsonData(LContent).AsJSON {$ELSE}{$IF CompilerVersion > 27.0}TJSONValue(LContent).ToJSON{$ELSE}TJSONValue(LContent).ToString{$ENDIF}{$ENDIF};
LWebResponse.ContentType := 'application/json; Charset=' + Charset;
LWebResponse.ContentType := 'application/json; charset=' + Charset;
end;
end;
end;
Expand Down

0 comments on commit d31589d

Please sign in to comment.