Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have been trying to learn a bit about api clients.
You have an api at www.expamle.com/api and you need to be able to GET all users at www.expamle.com/api/users and also get them by id at www.example.com/api/users/{id} .

In your code do you need to have a separate function to get ALL records and only one record?
What I don't get is how to properly serialize the results since when you get multiple records it returns you an array but it doesn't work with a single record.

Also, would you need more GET functions for other endpoints such as http://www.example.com/api/products/

What I have tried:

Currently im stuck at serializing an array or a single record on separate functions.
Posted
Updated 1-Jan-18 8:29am

1 solution

You just implement the methods you want your clients to use. In terms of different calls for getting one record and getting multiple\all records, they should be different methods so they can have different return types. One will return just the class type, the other an IEnumerable or IList of the class type.
 
Share this answer
 

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