POST Method Example

A POST request is used for adding a new resource to the REST service.

A POST request will usually require a serialized object to be included in the HTTP body.

postPet();
constants
    Endpoint = "https://petstore.swagger.io/v2";
    Path = "/pet";
vars
    client : JadeRestClient;
    response : JadeRestResponse;
    request : JadeRestRequest;
    pet : Pet;
begin
    client := create JadeRestClient(Endpoint) transient;
    request := create JadeRestRequest(Path) transient;
    create pet transient;
    pet.id := 314;
    pet.name := "Fluffy";
    pet.status := "available";
    request.dataFormat := request.DataFormat_JSON;
    request.addObjectParam(pet, Pet);
    create response transient;
    client.post(request, response);
    // We should get a 200 - Success.
    write response.statusCode;
epilog
    delete client;
    delete response;
    delete request;
    delete pet;
end;