Skip to content

Code4Delphi/csv-adapter-restrequest4delphi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CSV Adapter for RESTRequest4Delphi

This is the adapter for generating CSV files for RESTRequest4Delphi. Allows you to generate a text or CSV file with the content of a request.

📞 Contacts

     

✳ Prerequisites

This adapter must be used together with RESTRequest4Delphi

⚡ Installation

  • Installation using the Boss:
boss install github.com/Code4Delphi/csv-adapter-restrequest4delphi
  • Manual installation: Open your Delphi and add the following folder to your project, under Project > Options > Building > Delphi Compiler > Search path
csv-adapter-restrequest4delphi\Src

🚀 Quickstart

  • Add uses to your system:
uses
  CSV.Adapter.RESTRequest4D;
  • Getting the CSV for a TString:
begin
  TRequest.New.BaseURL('http://localhost:9050/clients')
    .Adapters(TCSVAdapterRESTRequest4D.New(Memo1.Lines, 'optional-root-element'))
    .Accept('application/json')
    .Get;
end;
  • Automatically saving CSV to a file:
begin
  TRequest.New.BaseURL('http://localhost:9050/clients')
    .Adapters(TCSVAdapterRESTRequest4D.New('C:\Temp\MyFile.csv', 'optional-root-element'))
    .Accept('application/json')
    .Get;
end;

⚙ Configurations

You can customize resources through the TCSVAdapterRESTRequest4DConfig class:

  • With Inline Settings
TRequest.New.BaseURL('http://localhost:9050/clients')
    .Adapters(TCSVAdapterRESTRequest4D.New('C:\Temp\MyFile.csv', 'optional-root-element', TCSVAdapterRESTRequest4DConfig.New.Separator('|')))
    .Accept('application/json')
    .Get;
  • With Settings in variable
procedure TViewMain.Button1Click(Sender: TObject);
var
  LResponse: IResponse;
  LConfig: ICSVAdapterRESTRequest4DConfig;
begin
  LConfig := TCSVAdapterRESTRequest4DConfig.New.Separator(cBoxSeparator.Text);

  LResponse := TRequest.New
    .BaseURL(edtBaseURL.Text)
    .Resource(edtResource.Text)
    .Adapters(TCSVAdapterRESTRequest4D.New('C:\Temp\MyFile.csv', 'optional-root-element', LConfig))
    .Accept('application/json')
    .Get;
end;

⌨️ Demo

  • Along with the project sources, you will find test projects. The API and Client project are respectively in the folders:
csv-adapter-restrequest4delphi\Samples\API
csv-adapter-restrequest4delphi\Client

image

💬 Contributions / Ideas / Bug Fixes

To submit a pull request, follow these steps:

  1. Fork the project
  2. Create a new branch (git checkout -b minha-nova-funcionalidade)
  3. Make your changes
  4. Make the commit (git commit -am 'Functionality or adjustment message')
  5. Push the branch (git push origin Message about functionality or adjustment)
  6. Open a pull request