![WA | Embarcadero RAD Studio Delphi C++Builder Blogs wa](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/06/WA-9375265.jpg?resize=1140%2C694&ssl=1)
Do you want to add enterprise-grade Wolfram Alpha features to your applications? You can easily use Wolfram Alpha in our C++ Software and Delphi applications by using Wolfram|Alpha API from the Wolfram Alpha with free 2000 requests monthly. It is a RESTful server and very easy to set up and get data in JSON format, which means we can easily use the REST framework to connect this data.
Table of Contents
What is Wolfram Alpha?
Summarizing Wolfram Research’s own description, Wolfram Alpha is an expert-level knowledge database and capabilities to the broadest possible range of people from all professions to education levels. They work to accept completely free-form input and to serve as a knowledge engine that generates powerful results and presents them with maximum clarity. Wolfram Alpha is an ambitious, long-term intellectual endeavor that is intended to improve over a long period of time.
The Wolfram Alpha API allows clients to submit free-form queries similar to the queries one might enter at the Wolfram|Alpha website, and for the computed results to be returned in a variety of formats. It is implemented in a standard REST protocol using HTTP GET requests. Each result is returned as a descriptive XML or JSON structure wrapping the requested content format.
Note that the Full Results API gives access to all capabilities and output formats. To display full results as a single image, use the Simple Results API.
Using REST to integrate Wolfram Alpha
REST (Representational State Transfer) is a connectivity method that allows to get and post data to create interactive applications that use Web Services. REST uses a subset of HTTP. A Web service that uses this REST data transfer architecture is called a RESTful. This web service must provide its web resources in a text form and this service also allows contents to be read and modified with a stateless protocol and a predefined set of operations. REST is a new modern data transfer architecture that allows interoperability between the computer systems on the Internet that provide these services. REST is Backend as a Service (BaaS) can be used in REST Server or REST Client applications, it is an alternative to SOAP to access a Web service. client tutorial shows how to use the REST Client Library for accessing REST-based web services (REST stands for Representational State Transfer).
In C++ and Delphi , the REST library is available for all platforms that are supported by both of them. The REST Library framework focuses on JSON as the representation format. XML is not explicitly supported.
C++ Builder has many connectivity options like FireDAC SQL Connections to InterBase, IB Express, MSSQL, MySQL, PostgreSQL, SQLite, …; or TCP/IP Connections and many other connectivity options. C++ Builder has also REST-based connectivity as a Client or as a Server that provides you to do REST connections by the REST components that come with RAD Studio officially.
Using the REST Debugger
We can easily set up the components by using REST Debugger Tool in RAD Studio (C++ Builder or Delphi). You can launch REST Debugger from the Tools menu of RAD StudioThe Embarcadero REST Debugger(The Latest version is 10.4.2) empowers developers to explore, test, and ultimately understand how a RESTful web service works. Dive right into REST data with filterable JSON blobs, streamlined OAuth 1.0/2.0 authentication, and configurable request/resource parameters. You can directly copy and paste REST components from the REST Debugger to the RAD Studio, Delphi, or C++Builder IDE. This enables the configuration and consumption of REST services in Delphi or C++Builder apps with just a few clicks.
REST Debugger allows you to test your connections easily, you can easily reach or transfer your data. There is also a free version that can be used by other REST tools and it can be downloaded from RESTdebugger.
In RAD Studio there is a good tool REST Debugger to test REST Requests (Gets, Posts, …) and it is very easy to automatically set up the REST components with their parameters.
Getting Wolfram Alpha API
Wolfram Alpha API is very simple, here are the steps,
- Read details about Wolfram Alpha API from their API Documentation
- Sign Up to Wolfram Alpha API by clicking Get Started button. To use Wolfram Alpha, you must have a Wolfram ID (appid), and you must register and sign in at the Wolfram|Alpha Developer Portal.
- Upon logging in, go to the My Apps tab to start creating your first app with App Name: Your APPID will be used to define APP NAME and USAGE TYPE etc. Get your APPID Access Key from this screen.
![WA1b7392782 | Embarcadero RAD Studio Delphi C++Builder Blogs Creating a Wolfram Alpha API APP id](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/06/WA1b-7392782.png?resize=750%2C576&ssl=1)
4. Integrate into your application
Now you can test your connection with REST Debugger or with your REST Client applications.
Connecting and Setting Components with the REST Debugger
![WAREST3006217 | Embarcadero RAD Studio Delphi C++Builder Blogs Talking to Wolfram Alpha using the REST debugger](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/06/WA_REST-3006217.png?resize=750%2C484&ssl=1)
- In Request Tab:
Set Method GET and BaseURL to “http://api.wolframalpha.com/v2/query“, please check Wolfram Alpha API Documentation
Set Content-Type: application/json - In Parameters Tab: Add these parameters and values by clicking Add button in Request Parameters section:
appid = YOUR_API_ID (add your api id key here)
output = json
input = YOUR QUERY HERE (add your query here)
you must check their web page and examples for more query examples.
Simply we can get Population of Madagascar by using “Population of Madagascar” input query below by changing DEMO to YOUR_API_ID
1 |
http://api.wolframalpha.com/v2/query?appid=DEMO&input=population%20of%20madagascar |
To get any detailed information from the Wolfram Alpha, with REST Debugger, copy your URL with your API ID Key
One of the great feature of REST Debugger setups all components and features for your C++ Builder application. Just press to ‘Copy Components’, paste it to your form design.
Testing a REST connection to Wolfram Alpha by using REST Debugger settings
You can easily create a REST connection by using REST components and REST Debugger in C++ Builder.
- Create a new Multi-Device C++ Builder application, save all unit and project files to a folder (i.e WolframAlpha API )
- Set your WolframAlpha API Registration on their web page and use REST Debugger as described above.
If you copied components by using REST Debugger as given above, paste them to your form, and arrange their positions to see their names. - Add a Button (TButton) and a Memo (TMemo) component to see all JSON data.
- Double click to Button1, and modify as below,
1 2 3 4 5 6 |
void __fastcall TForm1::Button1Click(TObject *Sender) { RESTRequest1->Execute(); TJSONValue *jValue = RESTResponse1->JSONValue; Memo1->Lines->Add( jValue->ToString() ); } |
If you run your application you will see that it gets all data about all results in JSON format.
If you don’t want to use components copied by the REST Debugger, you can also manually follow the Tutorial using the REST Client Library from here
How to communicate with the Wolfram Alpha API using REST components.
Follow these steps
- Create a new Multi-Device C++ Builder application, save all unit and project files to a folder (i.e WolframAlpha API )
- Add a Button (TButton) and a Memo (TMemo) component to see all JSON data.
- Drag RESTClient (TRESTClient , RESTRequest (TRESTRequest) and RESTResponse (TRESTResponse) and arrange their positions to see their names.
- Click to RESTClient1, and on the Object Inspector window,
Set your WolframAlpha API Registration on their web page as described above - Set BaseURL to “http://api.wolframalpha.com/v2/query“, please check Wolfram Alpha API Documentation
Set Content-Type: application/json in As described Wolfram Alpha API Documentation
Double click to its Params and add these parameters;
appid = YOUR_API_ID (add your api id key here)
output = json
input = YOUR QUERY HERE (add your query here), here we will use Edit1->Text to get search text.
7. Add a Button, double click to add OnClick() event as below,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
RESTClient1->BaseURL = "http://api.wolframalpha.com/v2/query"; RESTClient1->Params->Clear(); RESTClient1->AddParameter( "output", "json", TRESTRequestParameterKind::pkGETorPOST); RESTClient1->AddParameter( "appid", "WKX96W-XEP47R....", TRESTRequestParameterKind::pkGETorPOST); // USE YOUR APPID HERE RESTClient1->AddParameter( "input", Edit1->Text, TRESTRequestParameterKind::pkGETorPOST); RESTRequest1->Resource = ""; RESTRequest1->Method = TRESTRequestMethod::rmGET; RESTRequest1->Response = RESTResponse1; RESTRequest1->Response->ContentType = "application/json"; RESTRequest1->Response->ContentEncoding="UTF-8"; RESTRequest1->Execute(); TJSONValue *jValue = RESTResponse1->JSONValue; Memo1->Lines->Clear(); Memo1->Lines->Add(jValue->ToString()); |
As you see, REST connection and APIs are very useful with all platforms, Wolfram Alpha API can be used with REST components it in C++ Builder, it is also possible in Delphi too. This is an example run when you query ” Copernicium”,
![WARun8226647 | Embarcadero RAD Studio Delphi C++Builder Blogs An image of the example output from the Wolfram Alpha API received via REST](https://i0.wp.com/blogs.embarcadero.com/wp-content/uploads/2021/06/WA_Run-8226647.png?resize=750%2C473&ssl=1)
C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. There is a free C++ Builder Community Edition for students, beginners and startups, it can be download from here and the professional developers can use the Professional, Architect or Enterprise versions of C++ Builder which has trial version and can be downloaded from here.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition