Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

SCIS Health Check

See more SCiS Schools Catalogue Examples

Demonstrates the SCIS (Schools Catalogue Information Service) health check API call.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.Http,
  Chilkat.StringBuilder,
  Chilkat.JsonObject;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  http: THttp;
  sbResponseBody: TStringBuilder;
  jResp: TJsonObject;
  respStatusCode: Integer;

begin
  success := False;

  //  This example assumes the Chilkat API to have been previously unlocked.
  //  See Global Unlock Sample for sample code.

  http := THttp.Create;

  //  Implements the following CURL command:

  //  curl -i -X GET --url https://api.scisdata.com/checkStatus -H 'Authorization: Basic ****'

  //  Use the following online tool to generate HTTP code from a CURL command
  //  Convert a cURL Command to HTTP Source Code

  //  This causes the "Authorization: Basic ****" to be added to each request.
  http.Login := 'myLogin';
  http.Password := 'myPassword';
  http.BasicAuth := True;

  sbResponseBody := TStringBuilder.Create;
  success := http.QuickGetSb('https://api.scisdata.com/checkStatus',sbResponseBody);
  if (success = False) then
    begin
      WriteLn(http.LastErrorText);
      Exit;
    end;

  jResp := TJsonObject.Create;
  jResp.LoadSb(sbResponseBody);
  jResp.EmitCompact := False;

  WriteLn('Response Body:');
  WriteLn(jResp.Emit());

  respStatusCode := http.LastStatus;
  WriteLn('Response Status Code = ' + respStatusCode);
  if (respStatusCode >= 400) then
    begin
      WriteLn('Response Header:');
      WriteLn(http.LastHeader);
      WriteLn('Failed.');
      Exit;
    end;

  //  Sample JSON response:
  //  (Sample code for parsing the JSON response is shown below)
  //  
  //  {
  //    "subscriptionStatus": {
  //      "messages": [
  //        "Connection to SCIS API is successful",
  //        "User has a valid SCIS Data subscription"
  //      ]
  //    }
  //  }


  http.Free;
  sbResponseBody.Free;
  jResp.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.