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 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.

BaseResponseEnvelope<> has only two 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:

public class GetPayerTypesResponse: BaseResponseEnvelope<GetPayerTypesResponse.PayerType>

`{

    public class PayerType
    {
        public string Description { get; set; }

        public string Ref { get; set; }
    }

}`

We put in each response only two common fields, but anybody can add needed properties in needed response by themself.

Clone this wiki locally