Note that there are some explanatory texts on larger screens.

plurals
  1. POServiceStack Request DTO design
    text
    copied! <p>I am a .Net developer used to develop web application on Microsoft Technologies. I am trying to educate myself to understand REST approach for web services. So far i am loving the ServiceStack framework. </p> <p>But sometimes i find myself to write services in a fashion that i am used to with WCF. So I have a question which bugs me.</p> <p>I have 2 request DTO's so 2 services like these:</p> <pre class="lang-cs prettyprint-override"><code>[Route("/bookinglimit", "GET")] [Authenticate] public class GetBookingLimit : IReturn&lt;GetBookingLimitResponse&gt; { public int Id { get; set; } } public class GetBookingLimitResponse { public int Id { get; set; } public int ShiftId { get; set; } public DateTime StartDate { get; set; } public DateTime EndDate { get; set; } public int Limit { get; set; } public ResponseStatus ResponseStatus { get; set; } } [Route("/bookinglimits", "GET")] [Authenticate] public class GetBookingLimits : IReturn&lt;GetBookingLimitsResponse&gt; { public DateTime Date { get; set; } } public class GetBookingLimitsResponse { public List&lt;GetBookingLimitResponse&gt; BookingLimits { get; set; } public ResponseStatus ResponseStatus { get; set; } } </code></pre> <p>As seen on these Request DTO's i have similar request DTO's nearly for every services and this seems like not DRY.</p> <p>I tried to use <code>GetBookingLimitResponse</code> class in a list inside <code>GetBookingLimitsResponse</code> for that reason <code>ResponseStatus</code> inside <code>GetBookingLimitResponse</code> class is dublicated in case i have an error on <code>GetBookingLimits</code> service.</p> <p>Also I have service implementations for these requests like :</p> <pre class="lang-cs prettyprint-override"><code>public class BookingLimitService : AppServiceBase { public IValidator&lt;AddBookingLimit&gt; AddBookingLimitValidator { get; set; } public GetBookingLimitResponse Get(GetBookingLimit request) { BookingLimit bookingLimit = new BookingLimitRepository().Get(request.Id); return new GetBookingLimitResponse { Id = bookingLimit.Id, ShiftId = bookingLimit.ShiftId, Limit = bookingLimit.Limit, StartDate = bookingLimit.StartDate, EndDate = bookingLimit.EndDate, }; } public GetBookingLimitsResponse Get(GetBookingLimits request) { List&lt;BookingLimit&gt; bookingLimits = new BookingLimitRepository().GetByRestaurantId(base.UserSession.RestaurantId); List&lt;GetBookingLimitResponse&gt; listResponse = new List&lt;GetBookingLimitResponse&gt;(); foreach (BookingLimit bookingLimit in bookingLimits) { listResponse.Add(new GetBookingLimitResponse { Id = bookingLimit.Id, ShiftId = bookingLimit.ShiftId, Limit = bookingLimit.Limit, StartDate = bookingLimit.StartDate, EndDate = bookingLimit.EndDate }); } return new GetBookingLimitsResponse { BookingLimits = listResponse.Where(l =&gt; l.EndDate.ToShortDateString() == request.Date.ToShortDateString() &amp;&amp; l.StartDate.ToShortDateString() == request.Date.ToShortDateString()).ToList() }; } } </code></pre> <p>As you see i also want to use Validation Feature here, so i have to write validation classes for every request DTO i have. So i have a feeling that i should keep my service number low by grouping similar services into one service.</p> <p>But the question here that pops up in my mind that should i send more information than client need for that request ?</p> <p>I think my way of thinking should change because i am not happy with current code which i wrote thinking like a WCF guy. </p> <p>Can someone show me the right direction to follow.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload