Ada Programming/Libraries/Web/AWS
AWS, the Ada Web Server, is a complete framework to develop Web based applications. The main part of AWS is the embedded web server. This small, yet powerful, Web server can be embedded into your application, so it will be able to talk with a standard Web browser. Around this Web server, a lot of services have been developed.
AWS supports SOAP Web Services and the REST architecture.
Sample code
Hello World
The famous Hello World demo for AWS, a complete Web server that will display "Hello world!" for every request made to localhost on port 8080.
withAWS.Default;withAWS.Response;withAWS.Server;withAWS.Status;procedureHello_WorldisWS : AWS.Server.HTTP;functionHW_CB (Request : AWS.Status.Data)returnAWS.Response.DataisbeginreturnAWS.Response.Build ("text/html", "Hello world !");endHW_CB;beginAWS.Server.Start (WS, "Hello World", Callback => HW_CB'Access);delay60.0; AWS.Server.Shutdown (WS);endHello_World;
Setting server configuration and waiting for an event
It is possible to pass configuration parameters for the server using a record. It is also possible to use a built-in procedure on AWS to wait for an event.
callbacks.adb
packagebodyCallbacksisfunctionHW_CB (Request : AWS.Status.Data)returnAWS.Response.DataisbeginreturnAWS.Response.Build ("text/html", "Hello world !");endHW_CB;endCallbacks;
callbacks.ads
withAWS.Status;withAWS.Response;packageCallbacksisfunctionHW_CB (Request : AWS.Status.Data)returnAWS.Response.Data;endCallbacks;
main.adb
withAWS.Config.Set;withAWS.Server;procedureMainisuseAWS; Host :constantString := "localhost"; Port :constant:= 8080; Web_Server : Server.HTTP; Web_Config : Config.Object;begin-- Setup Config.Set.Server_Host (Web_Config, Host); Config.Set.Server_Port (Web_Config, Port); -- Start the server Server.Start (Web_Server => Web_Server, Callback => Callbacks.HW_CB'Access, Config => Web_Config); -- Wait for the Q key Server.Wait (Server.Q_Key_Pressed); -- Stop the server Server.Shutdown (Web_Server);endMain;
REST
Interface with bitcoind JSON-RPC.
bitcoin.adb
withAWS.Client;withAWS.Headers;withAWS.Headers.Set;withAWS.Response;packagebodyBitcoinisfunctionGet_Wallet_InforeturnAWS.Response.Dataishdrs : AWS.Headers.List := AWS.Headers.Empty_List;beginAWS.Headers.Set.Add(hdrs, "Content-Type", "text/plain");returnAWS.Client.Post(URL => "http://127.0.0.1:8332/", Data => "{""jsonrpc"": ""1.0"", ""id"":""test"", ""method"": ""getwalletinfo"", ""params"": []}", User => "bitcoinrpcUSERNAME", Pwd => "bitcoinrpcPASSWORD", Headers => hdrs);endGet_Wallet_Info;endBitcoin;
Create the bitcoin.conf file by opening Bitcoin Core and clicking on the corresponding button on the options window. The following is an example configuration file. Then reopen bitcoin-qt or start the bitcoind daemon to start the server. The bitcoin-cli program and the testnet network can be used for testing RPC commands.
bitcoin.conf
# Expose the RPC/JSON API server=1 rpcuser=USERNAME rpcpassword=PASSWORD
See also
Wikipedia
Wikibook
External links
- Project Info
- https://github.com/adacore/aws/
- Download
- https://github.com/adacore/aws/releases