| 1 |
with AAA.Strings; |
| 2 |
|
| 3 |
package Minirest is |
| 4 |
|
| 5 |
Rest_Error : exception; |
| 6 |
|
| 7 |
type Status_Kinds is (Informative, -- 1xx |
| 8 |
Success, -- 2xx |
| 9 |
Redirect, -- 3xx |
| 10 |
Client_Error, -- 4xx |
| 11 |
Server_Error); -- 5xx |
| 12 |
|
| 13 |
type Parameters is private; |
| 14 |
-- A collection of arguments of type key + value |
| 15 |
|
| 16 |
No_Arguments : constant Parameters; |
| 17 |
|
| 18 |
function "and" (L : Parameters; R : Parameters) return Parameters; |
| 19 |
|
| 20 |
function "=" (Key, Value : String) return Parameters; |
| 21 |
|
| 22 |
type Response (Status : Status_Kinds; Status_Length : Natural) is tagged |
| 23 |
record |
| 24 |
Status_Line : String (1 .. Status_Length); |
| 25 |
Status_Code : Positive range 100 .. 599; |
| 26 |
Raw_Headers : AAA.Strings.Vector; |
| 27 |
Headers : AAA.Strings.Map; |
| 28 |
Content : AAA.Strings.Vector; |
| 29 |
end record; |
| 30 |
|
| 31 |
function Succeeded (This : Response) return Boolean |
| 32 |
is (This.Status = Success); |
| 33 |
|
| 34 |
function Get (URL : String; |
| 35 |
Arguments : Parameters := No_Arguments; -- these are ?key=val |
| 36 |
Headers : Parameters := No_Arguments) -- these are Key: Val |
| 37 |
return Response; |
| 38 |
-- Use GET to retrieve URL; may raise Rest_Error for unexpected situations. |
| 39 |
-- Headers are passed via -H switch to curl. |
| 40 |
|
| 41 |
private |
| 42 |
|
| 43 |
type Parameters is record |
| 44 |
Data : AAA.Strings.Map; |
| 45 |
end record; |
| 46 |
|
| 47 |
No_Arguments : constant Parameters := (Data => AAA.Strings.Empty_Map); |
| 48 |
|
| 49 |
end Minirest; |