Skip to content

Request & Response

iAlexeyProkhorov edited this page Mar 21, 2020 · 7 revisions

Requests to Nova Poshta API and received responses it's a very long and strange story. When I start to use this API all was great, because I thought that they're use some common design for all requests and all responses. Unfortunately it's not so 😐.

Requests

Usually requests has one common structure. It's looks next:

{ "modelName": "model name", "calledMethod": "method name", "methodProperties": {... request body ...}, "apiKey": "[your api key]" }

In our client we call it Envelope and create special interface IRequestEnvelope<> for this. RequestEnvelope<> class are implement IRequestEnvelope<> by default. When we create request envelope instance we need to send also request properties type to this instance. By default we use EmptyRequest, for example:

var request = new RequestEnvelope<EmptyRequest>();

Responses

Like requests, responses in our client has envelope too. It's represents via IResponseEnvelope interface, which implements BaseResponseEnvelope abstract class.

On my opinion responses - it's a main Nova Poshta API problem, because it's absolut chaos. Looks like each method was wrote by different developers team, because almost each response are different and unique.

Each response has only two same properties:

  • Success - displays that your request was correct and you receive some data from API;
  • Data - array of received data;

That's why each API response presented by separated class, which include subclass which represent response data item. Example:

[DataContract] public class GetPayerTypesResponse: BaseResponseEnvelope<GetPayerTypesResponse.PayerType> { /// <summary> /// Represents payer type /// </summary> [DataContract] public class PayerType { /// <summary> /// Gets or sets payer type description on Ukrainian /// </summary> [DataMember] public string Description { get; set; }

        `/// <summary>`
        `/// Gets or sets payer type reference name`
        `/// </summary>`
        `[DataMember]`
        `public string Ref { get; set; }`

        `public override string ToString()`
        `{`
            `return Description;`
        `}`
    `}`
`}`
Clone this wiki locally