If you need to find shortest (not fastest) route, you can solve using a distance-based cost attribute. The name of such attribute depends on particular network dataset service is working with, e.g. in case of Route service on sampleserver3.arcgisonline.com this is the "Length" cost attribute. List of available attributes can be found in the REST service directory e.g. http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Network/USA/NAServer/Route
So, if you are solving based on a Distance cost attribute (shortest path):
In another case, when route is built using a Time-based cost attribute (fastest route), in order to return length of the built route (Distance value), you will need ask the service to accumulate Distance-based costs along the route using the accumulateAttributeNames parameter, e.g.: