GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together. Skip to content. Permalink Dismiss Join GitHub today GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together. Sign up. Branch: master. Find file Copy path. Cannot retrieve contributors at this time. Raw Blame History. Create Self ; FTimeOut. Create Self ; FProxyCredentials. CancelRequest; FResources.
SetAcceptTypes ResourceRequest. SetContentTypes ResourceRequest. SetHeaders vHeaders. SetAcceptedLanguages ResourceRequest. ConfigureTimeout FTimeOut. SetAsync ResourceRequest. Delete vUrl, ResourceRequest.
GetString TEncoding. GetBytes vResponseString. ToCharArray0vResponseString. Free; FResources. ResponseCode; end ; function TRestClient. Add Result ; end ; function TRestClient. StatusCode ; end ; procedure TRestClient. Free; end ; end ; function TResource. Free; end ; end ; procedure TResource.
CopyFrom Content, Content. Size ; FRestClient. Clear; if assigned Content then begin Content. Create; end ; procedure TResource. Delete ; begin FRestClient. Destroy; begin FRestClient. Extract Self ; FContent.
Free; FHeaders. Free; inherited ; end ; function TResource. FromJsonArray Adapter. ClassType, Adapter. Create vRawContent ; try vStream. CopyFrom vStream, vStream.About donations wiki. Computer Math and Games in Pascal. Lazarus Handbook.
Advanced search. How to make a queue in pa Member Posts: Is there an alternative REST client library available? DonAlfredo Hero Member Posts: Try the mORMot! TRestClient appears to be the perfect tool for this job, but I am unsure if it's available in Lazarus or not. JD Hero Member Posts: Windows 10, 7 - Lazarus 2. Jurassic Pork Hero Member Posts: Success on Windows 7 Lazarus 1.
REST Client Library
May be need to change the path to Indy files. SysUtils. Classes. RestRequest in 'RestRequest. RestResp : THttpResponse. Domain 'jsonplaceholder. Path 'todos'. Path '1'. Path 'posts'. Get. WriteLn RestResp. ResponseStr. Readln. Free. Writeln E.
ClassName': 'E. Message. Thank you for the helpful replies here. I am looking to be as cross-plat compatible as possible, and my dev box is actually a Debian box, so components which strictly depend on Windows libraries are a no-go. I will first give the RestRequest unit a shot, the one provided by Jurassic Porkalthough I'd wish for as little external deps as possible, I'll check it out and see how it works. As Leledumbo mentions, the only issue I may run into with rolling my own REST API client is dealing with authentication, but most endpoints just use a simple header, so that shouldn't be a big deal.I set the ConnectionTimeout to 2 minutes and the ResponseTimeout to minutes.
The server is a servlet written in Java and the session timeout there is 30 minutes. Despite the above, after 30 seconds or so, the connection is terminated and the response is nil as if something broke it in the middle of the work.
How can I know if it's a client side or a server side? Am I missing something with the responsetimeout I set? Indy is very reliable and it allowed me to create my REST service without any problem. Run ; and then with some anonymous function I used to handle the async response. I had spent 3 hours on this which is nothing compared to the 2 days I had spent with REST components trying to figure out what was wrong.
This is my experience and, as I have already said, bugs may have been fixed.
Subscribe to RSS
I am telling you the problems that I found so you can save your time or see if the components now work properly. There are many more that can be useful to you, check on Google! I ask because out of all the things you wrote, the timeout issue is the only thing I'm dealing with now and have no clue what's going on.
I do know that when the servlet is running locally, it's working flawlessly and when running remotely, I get disconnections, not sure if it's timeout related or not. I will give indy a try though I preferred to use built in components and not 3rd party ones.
I understand that the component that came with Also, will I need the external ssl dll files for it to work with https? If you are using the latest version of the IDE you should also have the latest version or one of the most recent. I always used Indy and ICS. It is very fast and works https without extra DLL.
A single component to the rescue.! I tried the TRestClient component family but they seemed to be over complicated I just ruled them out. One last thing is to understand the disconnections I have, not sure if it's client or server side. Any tips on finding that out? This was back with XE8 and I ended up just building the app in Swift. Just curious, what issues you had?
You need to be a member in order to leave a comment. Sign up for a new account in our community. It's easy! Already have an account? Sign in here. Network, Cloud and Web.
Search In. Delphi The library is available for all platforms that are supported by Delphi. The framework focuses on JSON as the representation format. XML is not explicitly supported. The concept of the REST components is built around a troika of three main components: the request, the client, and the response. All of them are part of the workflow when fetching data from a service. Authenticators described later can be attached to the client for a convenient way of adding authentication to a request.
One of the most important properties of the client is the BaseURL. The base-url is the primary endpoint of a service-provider and typically remains constant for all requests to this provider. All requests are directed to this endpoint, so the base-url is the 'first half' of the complete request-url. The 'second half' is the 'resource', and it is provided by the request-component.
The documentation of the service-provider typically contains information about the url-structure. The client only throws 'hard' exceptions, connection failures, and so on.
The request REST. When connected to a client-component, it can be executed even at design time. One of the most important properties of the request is the 'Resource'. This value forms the previously mentioned 'second half' of the full request-url and defines the actual action that is executed on the service.
The request also defines the HTTP methods 'get', 'post', 'put', 'delete' that are used for its execution. These parameters consist only of a value and are integrated into the body of the request.
You can use the property AutoCreateParams to control this behavior. All parameters are encoded automatically to match the requirements of a valid HTTP request per default. There might be scenarios in which the value of the parameter is already encoded and does not need to be encoded again. The response holds all the returned data from the service. A response object can be created on the fly by the client while executing a request, or the response object can be created beforehand and then connected to a client before executing a request.
Most services require an authentication before they can be used. The authenticator classes are used to apply the specific authentication methods that are required by the REST service. An authenticator is attached to the client and is automatically executed on each executed request. After the property is configured, it can be used for as many requests as needed, without touching them again.
Typically, the authenticator works as a decorator for the request by adding headers or other parameters to it. Because of the variety of existing authentication methods, it would not be sufficient to provide only a single authenticator. A flexible framework was created instead, allowing to authenticate against a lot of different methods. A couple of standard authenticators are included in the component set, and custom authenticators can easily be integrated see below.
The simple authenticator mimics a basic authentication like an HTML form containing an input field for a username and another one for a password. Next to the username and the password itself, this authenticator also requires the names of the keys. The value for a username could be transmitted as 'user', 'username', or maybe as simple as 'u'. Depending on the method of the request, the data is transmitted either in the URL for a get request unsecure or in the body for a post request.
The basic authenticator addresses the HTTP basic authentication. It embeds a value containing the username and password into the HTTP header of the request.GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
If nothing happens, download GitHub Desktop and try again. If nothing happens, download Xcode and try again. If nothing happens, download the GitHub extension for Visual Studio and try again. The API it is designed to work with Delphi 7 or later.
Newer versions takes advantage of Generics Methods.
There are a IHttpConnection interface to abstract the real Http conection. Indy 9 does not handles HTTP response codes correctly, then if you are using Delphi 7, you must update your indy library to version 10 or use WinHttp recommended. The objects are transmitted in JSON format.
To function properly, the object must be declared as follows, with public fields. See more details about serialization here: Serialization. Note that all code below assume you have installed the component in your IDE and dropped the RestClient component on a form or data module, but of course you can also create the component directly in your code.
Any thought about how to implement this feature for Indy and WinInet are welcome. Send forms with file attachments is possible by declaring a class that represents the form fields and inherits from TMultiPartFormData. You can set credentials using the SetCredentials method before making the first request:.
Indy note: Certificate validation is not yet supported with Indy. Certificates will not be validated! Any thought about how to implement this feature for Indy are welcome.
The dark mode beta is finally here. Change your preferences any time. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.
Learn more. Asked 2 years, 5 months ago. Active 3 months ago. Viewed 2k times. Currently only able to receive text. Mylon Mylon 35 1 1 silver badge 7 7 bronze badges. You are able to receive only text becuase the response is supposed to be only text.
Do a Google search for more info but that set of components can only get a string from the server like some typical json and then store the response. Avoid using TStream for this sort of thing because there are problems with it. It may be least hassle to transfer your file encoded using Base64 as a string and decode it on the client side.
If you need to download an executable, a word file or whatever use Indy or something else. This doesn't sound like REST which you're dealing with. REST is meant for data exchange Otherwise, you should use just plain HTTP communication. Typically, in a REST response, if it includes file data, one of the members of the response will be a text representation of the file, which can be Base64 encoded data. It's very hard to tell without any information about the response your dealing with.
Active Oldest Votes. Get 'info'. Free; end; end; deQuotedString function: function TForm1. Aqil Aqil 2 2 silver badges 16 16 bronze badges. It's like the delphi XE TRestResponse is not good for binary data. Use idHTTP. Create; idHttp1. Charlie Charlie 14k 5 5 gold badges 38 38 silver badges 64 64 bronze badges. More specifically, downloading repositories from GitHub.
Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password.The library is available for all platforms that are supported by Delphi. XML is not explicitly supported. Set Form. Save All. BaseURL " property. Resource " property. Params, enter " Kelly Clarkson " as the " Artist-Name". So that's all we need to do!
These three components are automatically hooked up by the designer. To see the data, let's use Live Bindings. Content" property and select "Link to New Control". Select TMemo from the "Bind to new Control" list. Check "Add control label". In the Object Inspector, set the " MemoContent.
Subscribe to RSS
WordWrap" property to "True". Add a "TButton" to the form. In the Object Inspector, set Button1. Double-click on the button and in the OnClick event enter this line of code to execute the request:. Run the project F9click on the button to see the response from the service. Change the artist name to something different i. Michael Jacksonclick again and observe different response displayed in the memo.
Stop the application. We might be interested in displaying just a subset some specific content returned of the JSON response. JSON has a path, like "resp. Site Search User. Share Subscribe by email More Cancel. In the Object Inspector: a. The three components have these default members. Click OK.
Reposition and resize the Memo1 component.