In RESTful Web Services, should Response DTOs contain their child DTOs?
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , To be RESTful you don't necessarily have to return the full representation of the resource You do however want to enable hypermedia as means to get/set all the information the user of your API needs (Hypermedia as the engine of application state - a.k.a. HATEOAS) To satisfy that you can either use the suggestion by @bowmanb to put a URI for all the locations or add individual URIs for each of the locations. You probably want to add additional URIs for other options of doing something with the resource.
|
Web API 2.2 - ApiController to ODataController (changing Content Type after setting Formatter)
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Actually I got it working the way I wanted, more or less, by using OWIN and writing my own middleware. Basically I wanted a way to force a content-type without having to write a specific oData formatter for each instance. So oData could continue to format whichever way it was told to, and I would just tell the browser to treat it as plain text (or whatever else I wanted it to be). public class OWINCustomMiddleware : OwinMiddleware {
public OWINCustomMiddleware(OwinMiddleware next): base(next) {
}
public async override Task Invoke(IOwinContext context) {
//Check if a content-type coercion querystring token is present
if (context.Request.QueryString.HasValue) {
NameValueCollection queryString = HttpUtility.ParseQueryString(context.Request.QueryString.Value);
String coerce = queryString.Get("$coerce");
if (!String.IsNullOrWhiteSpace(coerce)) {
//Remove $coerce token so it doesn't impact future methods
queryString.Remove("$coerce");
context.Request.QueryString = new QueryString(queryString.ToString());
//Append a header to the request, to be later used in Response Content-Type coercion
context.Request.Headers.Add("coerce", new String[] { coerce });
}
}
await Next.Invoke(context);
//Coerce existing response content-type to value of coerce header (if present)
if (context.Request.Headers != null) {
if (context.Request.Headers["coerce"] != null) {
Int32 index = context.Response.ContentType.IndexOf(';');
if (index > 0) {
context.Response.ContentType = context.Request.Headers["coerce"] + context.Response.ContentType.Substring(index, context.Response.ContentType.Length - index);
} else {
context.Response.ContentType = context.Request.Headers["coerce"];
}
}
}
}
}
|
Should input DTOs for RESTful endpoints match the output DTOs?
Tag : rest , By : James Cary
Date : March 29 2020, 07:55 AM
This might help you It seems the REST consensus is that when updating using PUT, one supplies the entire entity to replace. Programmatically, it would work having PUT /person/{id} accepting input which behind the scenes maps to UpdatePersonDTO instead of Person.
|
odata query works again ApiController but does not work again ODataController
Date : March 29 2020, 07:55 AM
With these it helps First, from the namespace System.Web.OData.ODataController, I think you are using the Web API OData V4 library. V4 doesn't accept application/atomsvc+xml because only "Json" is the standard in OData V4 spec. Second, odata=fullmetadata is the OData V3 metadata header, for V4, it should be odata.metadata=full
|
WebApi (ApiController) vs OData (ODataController) in ASP.Net MVC
Date : March 29 2020, 07:55 AM
|