Reputation: 40140
A dumb question, I know. But I don't normally do web programming and have been asked to send some JSON data and receive some in return.
I googled and it is clear how to encode and decode the JSON data, but I am so new to this that I don't know how to communicate with the given URL and say "here's some data, please send me some back".
Can anyone point me at a simple working code example? For instance, just to pass user_name and password as JSON and to receive some reply ... I think I should be using TIdHTTP
, but am not sure how to use it with JSON. I have one GET and one POST interface.
+1 to @DavidHeffernan but I don't understand who to pass the packed JSON data with my request or to retrieve it from the response. En/de-code is fine, but adding it as parameters has me bogged down.
I really would appreciate a (link to a) small, but complete working example.
Btw, I only have XE2 starter edition, so I don't have datasnap.
Upvotes: 0
Views: 15277
Reputation: 43023
For the JSON process via HTTP, take a look at the following S/O question: https://stackoverflow.com/a/15948106/458259
If your problem is about how to consume a remote RESTful service in Delphi, you will find it the answer.
But if you want to communicate between Delphi applications using JSON and HTTP, the easiest is to implemenent a RESTful Client-Server connection in Delphi.
For Client-Server transmission using JSON and RESTful, take a look at our Open Source Synopse mORMot framework. It will do all the JSON serialization and RESTful routing for you.
It features a Client-Server ORM (perhaps not what you need here).
But also a SOA framework using two modes:
You can chose either mode to use JSON communication over HTTP.
Note that mORMot is expected to work with Delphi XE2 starter edition, since it does not use any "advanced" feature of the Pro/Entreprise/Architect editions, like DB.pas or DataSnap. And it will allow you to access databases, even with a starter edition. In case of difficulties due to something missing in the Starter, please feel free to report the problem on our forum.
Upvotes: 1