1
votes

I am trying to get all equipment types from my API using the following code.

client = new JsonServiceClient(environment.apiEndpoint);
var equipmentTypes = new GetEquipmentTypes();
var response = this.client.get(equipmentTypes);

I can see that it is in the network tab. The data is being transferred.

public class GetEquipmentTypeResponse

{
    public IEnumerable<EquipmentType> Results { get; set; }
    public ResponseStatus ResponseStatus { get; set; }
}

Is the return DTO from the API.

[Route("/api/EquipmentTypes", "GET")]
public class GetEquipmentTypes : IReturn<GetEquipmentTypeResponse>
{

}

Is the ServiceInterface used.

IEnumerable<EquipmentType> response = db.Select<EquipmentType>(x=>x.Name == request.Name);
return new GetEquipmentTypeResponse { Results = response, 
                                     ResponseStatus = new ResponseStatus { }};

Is what the API returns.

The API is written in asp.net. The client side is angular 6 (typescript).

I have attached two images, which is the request and the response given.

Request This is the request which is sent to the API.

Response from API This is what the API responds.

What I get in ts. This is what I get from var response. (console.log(response))

1
It's impossible for anyone to diagnose any potential issues without any info on what's actually being sent or what the response is. It's not even clear what language is being used as the code suggests C# but client.get() is not an API in C# clients. At a minimum you should show the full HTTP Request/Response Headers, the API endpoints/BaseUrl used. Also not cause of the issue but you shouldn't use Interfaces in DTOs (just use List) or populate ResponseStatus unless you want to return a custom Error Response. - mythz
Yeah, sorry for the lack of details. I have updated the question now. Do you mean that I should not return IEnumerable of equipmentType? just a List<EquipmentType>. I tried to follow the example from docs.servicestack.net/api-design. - Atle Kristiansen
Right don't use interfaces in DTOs, use Concrete collections like List<T> instead. - mythz

1 Answers

1
votes

The screenshot shows that the response is being returned fine, the Promise result is just not being awaited, try:

var response = await this.client.get(equipmentTypes);