Click here to Skip to main content
16,022,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to Restful API and need help on creating one in C#. I have a JSON from that API. I also need help to create a web page to call your API, parse the data and display the product details.

Create a RESTful API using C#, and return the JSON data attached. - this API will require authentication, you can define temporary user name / pwd for token authentication - Require request Id = 385 - Return the JSON in the attachment, you can hardcode it - Properly handle different status code

Create a web page component to display the data you return from the API you created in requirement #1, prefer technology React.js (you may use your favorite technology) - Implement your logic how to call your API - Proper handle exception if API failed. - Create React component or function to display the product details coming back from your API - Properties to display: all different labels with values, for example:

"label": "Lookup State", "stateCode": "CA", "stateDesc": "California"
In the web page, it should display like this: Lookup State: CA

Other properties required to display: all Description, ABV, Proof, Liters, Item and Item properties.
Implement your web page with good responsiveness.
Proper handle empty data


Here is the JSON:
JSON
  1  {
  2      "rowidObject": "385\t",
  3      "label": "Corporate MDM ID - 101360",
  4      "ExDoNotUse": "N",
  5      "ExBarrel": "N",
  6      "ExUPC": "999999999999",
  7      "ExSCC": "99999999999999",
  8      "ExCorpMDMID": "101360",
  9      "ExRefOnly": "N",
 10      "ExProductSKU_ExUnitOfMeasure_1_rowidObject": "20797\t",
 11      "ExProductSKU_rowidObject": "300126\t",
 12      "ExRefProduct": {
 13          "ExVntgCrp": "0",
 14          "ExProof": ".00",
 15          "ExItemLife": "0",
 16          "ExABV": ".00",
 17          "ExDscrptnFull": "Clos Du Bois Merlot Wnmkr",
 18          "ExCrpCrtfd": "N",
 19          "ExVntgSnstvCrp": "N",
 20          "ExDscrptn": "Clos Du Bois Merlot Wnmkr",
 21          "ExCrpClass": {
 22              "rowidObject": "1\t",
 23              "label": "Lookup Product Corporate Class",
 24              "ExCorporateClassDesc": "High Wine (>14.5%)",
 25              "ExCrpClassID": "High Wine (>14.5%)"
 26          },
 27          "ExTempProtectionFlg": "N",
 28          "ExUnitOfMeasure": {
 29              "ExCasesPerPallet": "0",
 30              "ExLiters": "6.0000000",
 31              "ExCaseWidth": "1.0000",
 32              "ExCaseHeight": "1.0000",
 33              "ExGallonage": "1.5850320",
 34              "ExCaseWeight": ".00",
 35              "ExCaseLength": "1.0000",
 36              "ExCasesPerLayer": "0",
 37              "ExTrueBtlsPerCase": "1",
 38              "ExCaseEqvlnt": "1.000",
 39              "ExBttlCase": "1",
 40              "ExMultiPack": "0"
 41          },
 42          "ExProductContainer": {
 43              "link": [],
 44              "firstRecord": 1,
 45              "pageSize": 100,
 46              "searchToken": "multi",
 47              "item": [
 48                  {
 49                      "rowidObject": "295733\t",
 50                      "label": "SKU to Container Relationship",
 51                      "ExPalletType": "Standard (43.1In - 65In)",
 52                      "ExCntnrType": {
 53                          "rowidObject": "12\t",
 54                          "label": "Lookup Product Container Type",
 55                          "ExCntnrTypeDesc": "Other",
 56                          "ExCntnrTypeID": "Other"
 57                      },
 58                      "ExClosureTyp": {
 59                          "rowidObject": "3\t",
 60                          "label": "Lookup Product Closure Type",
 61                          "ExClsrTypeDesc": "Cork",
 62                          "ExClsrTypId": "Cork"
 63                      },
 64                      "ExSzDscrptr": {
 65                          "rowidObject": "285\t",
 66                          "label": "Lookup Product Size Descriptor",
 67                          "ExSizeDesc": "6L",
 68                          "ExSzDscrptrID": "6L"
 69                      },
 70                      "ExProductLabel": {
 71                          "link": [],
 72                          "firstRecord": 1,
 73                          "pageSize": 100,
 74                          "searchToken": "multi",
 75                          "item": [
 76                              {
 77                                  "rowidObject": "288511\t",
 78                                  "label": "Label Container Rel",
 79                                  "ExColor": {
 80                                      "rowidObject": "7\t",
 81                                      "label": "Lookup Product Color",
 82                                      "ExColorDesc": "Red",
 83                                      "ExColorID": "Red"
 84                                  },
 85                                  "ExLabelNm": "Clos Du Bois Wnmkr Merlot",
 86                                  "ExRegion": "N/A WINE",
 87                                  "ExState": {
 88                                      "rowidObject": "6\t",
 89                                      "label": "Lookup State",
 90                                      "stateCode": "CA",
 91                                      "stateDesc": "California"
 92                                  },
 93                                  "ExCountry": {
 94                                      "rowidObject": "228\t",
 95                                      "label": "Lookup Country",
 96                                      "countryCode": "US",
 97                                      "countryDesc": "United States"
 98                                  },
 99                                  "ExProductBrand": {
100                                      "link": [],
101                                      "firstRecord": 1,
102                                      "pageSize": 100,
103                                      "searchToken": "multi",
104                                      "item": [
105                                          {
106                                              "rowidObject": "2554\t",
107                                              "label": "Brand Label Relationship",
108                                              "ExBrandNm": "Clos Du Bois"
109                                          }
110                                      ]
111                                  }
112                              }
113                          ]
114                      }
115                  }
116              ]
117          }
118      },
119      "ExProductAltId": {
120          "link": [],
121          "firstRecord": 1,
122          "pageSize": 100,
123          "searchToken": "multi",
124          "item": [
125              {
126                  "rowidObject": "1005579\t",
127                  "label": "Product Alternate Indentifier",
128                  "ExAltID": "3829565",
129                  "ExAltIDType": {
130                      "rowidObject": "15\t",
131                      "label": "Lookup Product Alternate ID",
132                      "ExAltIDTypeDesc": "Data Warehouse",
133                      "ExAltIDType": "EDW ID"
134                  }
135              }
136          ]
137      }
138  }


What I have tried:

I think I have created the right Classes for the Json Property:

C#
  1  public class ExAltIDType
  2  {
  3      public Guid rowidObject { get; set; }
  4      public string label { get; set; }
  5      public string ExAltIDTypeDesc { get; set; }
  6      public string ExAltIDType { get; set; }
  7  }
  8  
  9  public class ExClosureTyp
 10  {
 11      public Guid rowidObject { get; set; }
 12      public string label { get; set; }
 13      public string ExClsrTypeDesc { get; set; }
 14      public string ExClsrTypId { get; set; }
 15  }
 16  
 17  public class ExCntnrType
 18  {
 19      public Guid rowidObject { get; set; }
 20      public string label { get; set; }
 21      public string ExCntnrTypeDesc { get; set; }
 22      public string ExCntnrTypeID { get; set; }
 23  }
 24  
 25  public class ExColor
 26  {
 27      public Guid rowidObject { get; set; }
 28      public string label { get; set; }
 29      public string ExColorDesc { get; set; }
 30      public string ExColorID { get; set; }
 31  }
 32  
 33  public class ExCountry
 34  {
 35      public Guid rowidObject { get; set; }
 36      public string label { get; set; }
 37      public string countryCode { get; set; }
 38      public string countryDesc { get; set; }
 39  }
 40  
 41  public class ExCrpClass
 42  {
 43      public Guid rowidObject { get; set; }
 44      public string label { get; set; }
 45      public string ExCorporateClassDesc { get; set; }
 46      public string ExCrpClassID { get; set; }
 47  }
 48  
 49  public class ExProductAltId
 50  {
 51      public List<object> link { get; set; }
 52      public int firstRecord { get; set; }
 53      public int pageSize { get; set; }
 54      public string searchToken { get; set; }
 55      public List<Item> item { get; set; }
 56  }
 57  
 58  public class ExProductBrand
 59  {
 60      public List<object> link { get; set; }
 61      public int firstRecord { get; set; }
 62      public int pageSize { get; set; }
 63      public string searchToken { get; set; }
 64      public List<Item> item { get; set; }
 65  }
 66  
 67  public class ExProductContainer
 68  {
 69      public List<object> link { get; set; }
 70      public int firstRecord { get; set; }
 71      public int pageSize { get; set; }
 72      public string searchToken { get; set; }
 73      public List<Item> item { get; set; }
 74  }
 75  
 76  public class ExProductLabel
 77  {
 78      public List<object> link { get; set; }
 79      public int firstRecord { get; set; }
 80      public int pageSize { get; set; }
 81      public string searchToken { get; set; }
 82      public List<Item> item { get; set; }
 83  }
 84  
 85  public class ExRefProduct
 86  {
 87      public string ExVntgCrp { get; set; }
 88      public string ExProof { get; set; }
 89      public string ExItemLife { get; set; }
 90      public string ExABV { get; set; }
 91      public string ExDscrptnFull { get; set; }
 92      public string ExCrpCrtfd { get; set; }
 93      public string ExVntgSnstvCrp { get; set; }
 94      public string ExDscrptn { get; set; }
 95      public ExCrpClass ExCrpClass { get; set; }
 96      public string ExTempProtectionFlg { get; set; }
 97      public ExUnitOfMeasure ExUnitOfMeasure { get; set; }
 98      public ExProductContainer ExProductContainer { get; set; }
 99  }
100  
101  public class ExState
102  {
103      public Guid rowidObject { get; set; }
104      public string label { get; set; }
105      public string stateCode { get; set; }
106      public string stateDesc { get; set; }
107  }
108  
109  public class ExSzDscrptr
110  {
111      public Guid rowidObject { get; set; }
112      public string label { get; set; }
113      public string ExSizeDesc { get; set; }
114      public string ExSzDscrptrID { get; set; }
115  }
116  
117  public class ExUnitOfMeasure
118  {
119      public string ExCasesPerPallet { get; set; }
120      public string ExLiters { get; set; }
121      public string ExCaseWidth { get; set; }
122      public string ExCaseHeight { get; set; }
123      public string ExGallonage { get; set; }
124      public string ExCaseWeight { get; set; }
125      public string ExCaseLength { get; set; }
126      public string ExCasesPerLayer { get; set; }
127      public string ExTrueBtlsPerCase { get; set; }
128      public string ExCaseEqvlnt { get; set; }
129      public string ExBttlCase { get; set; }
130      public string ExMultiPack { get; set; }
131  }
132  
133  public class Item
134  {
135      public Guid rowidObject { get; set; }
136      public string label { get; set; }
137      public string ExPalletType { get; set; }
138      public ExCntnrType ExCntnrType { get; set; }
139      public ExClosureTyp ExClosureTyp { get; set; }
140      public ExSzDscrptr ExSzDscrptr { get; set; }
141      public ExProductLabel ExProductLabel { get; set; }
142      public ExColor ExColor { get; set; }
143      public string ExLabelNm { get; set; }
144      public string ExRegion { get; set; }
145      public ExState ExState { get; set; }
146      public ExCountry ExCountry { get; set; }
147      public ExProductBrand ExProductBrand { get; set; }
148      public string ExBrandNm { get; set; }
149      public string ExAltID { get; set; }
150      public ExAltIDType ExAltIDType { get; set; }
151  }
152  
153  public class Root
154  {
155      public Guid rowidObject { get; set; }
156      public string label { get; set; }
157      public string ExDoNotUse { get; set; }
158      public string ExBarrel { get; set; }
159      public string ExUPC { get; set; }
160      public string ExSCC { get; set; }
161      public string ExCorpMDMID { get; set; }
162      public string ExRefOnly { get; set; }
163      public string ExProductSKU_ExUnitOfMeasure_1_rowidObject { get; set; }
164      public string ExProductSKU_rowidObject { get; set; }
165      public ExRefProduct ExRefProduct { get; set; }
166      public ExProductAltId ExProductAltId { get; set; }
167  }
Posted
Updated 4-Jun-24 5:03am
v4

 
Share this answer
 
Comments
Computer Wiz99 4-Jun-24 10:05am    
Thanks. I have also updated the question.
This sounds very much like a homework question. Normally I would say that you should tackle this yourself but there are some things about this question that you should be raising with the person who set the data.

The first thing is the use of RESTful API. What you have presented is a JSON object. This does not constitute even the beginnings of a RESTful API; it is worth noting that REST is hard to do without lots of upfront design work while what you are showing is a simple get call.

The API requires authentication. Man oh man, this is a biggie. Connecting your client and server, and performing token authentication - that's not really beginner stuff. Check to see if you really need to perform token authentication.

Also, what response status? There's a mighty big assumption in that sentence that you're going to know what status you should be returning. You probably have three statuses that you're dealing with - 200 (OK), which goes with the returned data; 401 (not authenticated), for incorrect login details and 404 (not found), if the value passed across doesn't match the one you're expecting.

The important thing to remember about building systems is that you should be starting with the design. Work out what the actual requirements are, and ask questions. Clarify anything that is an assumption, or which is ambiguous. Only when you have figured all of this out should you start trying to actually build the system.

I wish you good luck.
 
Share this answer
 
Comments
Computer Wiz99 4-Jun-24 12:30pm    
Thanks you very much. I thought that I was going crazy. I guess we are tested to pick up all of that what you just said.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900