lundi 11 juin 2018

Using RestSharp to create a API client - Design Pattern

• Hi – I am new to c#/.Net and API programming.
• I am wanting to create a c# .Net API client for an accounting web app.
• I intend to use RestSharp.
• Each request method for the API contains a Payload which consists of a Header and a Body (see below).

  • The 'Header' fields are the same for all methods, except the values
    will differ for each submission.

  • The fields within the Body field are different for ALL the different API methods.

    1. Should I instantiate a Payload object and pass it to a Restsharp request using AddParameter method?#
    2. As the Payload field for different API methods will only differ by the fields of the Body field, what design pattern should I use to construct the appropriate payload for a specific API method using JSON POCO classes?

Thanks in advance for your assistance.

    {
  "payload": {
    "Header": {
      "MessageType": "Request",
      "SubmissionNumber": "00000001",
      "Authentication": {
        "AccNumber": "123456",
        "MD5Value": "7dd259dea3393880406d292e3f6f5830",
        "ApplicationID": "appID"
      }
    },
    "Body": {
      "SearchParameters": {
        "ReturnCount": "10",
        "Offset": "0",
        "OrderResultsBy": "TransactionDate",
        "OrderDirection": "ASC",
        "NominalCode": "1200"
      }

Aucun commentaire:

Enregistrer un commentaire