dotarj / partialresponse Goto Github PK
View Code? Open in Web Editor NEWPartialResponse provides JSON partial response (partial resource) support for ASP.NET Web API.
License: Other
PartialResponse provides JSON partial response (partial resource) support for ASP.NET Web API.
License: Other
Hi-
I recently installed WebApi.PartialReponse and everything was working great until I noticed an error on the help pages that are generated via Microsoft.AspNet.WebApi.HelpPage.
If I leave the config set as:
GlobalConfiguration.Configuration.Formatters.Add(new JsonMediaTypeFormatter());
it generates the response format samples as expected:
Sample: { "method": "200.8", "context": "USEPA", "desc": "Metals in Waters by ICP/MS" }
However, when I change the config so partial responses actually work:
GlobalConfiguration.Configuration.Formatters.Add(new PartialJsonMediaTypeFormatter() {IgnoreCase = true });
I get the following error message when it tries to create the sample response:
An exception has occurred while using the formatter 'PartialJsonMediaTypeFormatter' to generate sample for media type 'application/json'. Exception message: Value cannot be null. Parameter name: request
It generates another, similar message for media type 'text/json' as well.
It seems like the helpfile stuff isn't recognized the PartialJsonMediaTypeFormatter as JSON, and I'm not sure if that's on their end or if there's some way to force it in the configuration. Thanks!
Hi
In my project I try to use partial response. I have following response model:
{
"Limit": 0,
"Offset": 0,
"Total": 0,
"Content": [
{Some model},
{Some model}
]
}
If I specify nested properties of Content
without leading spaces, anything works OK and I receive proper response. For request fields=limit,content(Id,name)
I receive:
{
"Limit": 20,
"Content": [
{
"Id": "9b71be7c-0b29-419d-a89d-23cde2b2a0e0",
"Name": "string"
},
{
"Id": "468ace91-84a4-4d99-8026-aec839519686",
"Name": "string"
}
]
}
But if I create request with space before nested property specification only direct properties will be serialized. For example for request fields=limit, content(Id,name)
I receive:
{
"Limit": 20
}
If create request without nested properties or specify nested property one by one (with /
character), anything works fine
Hi Arjen,
Well done for Partial Response , could not be easier to implement this. I appreciate your work. Now, I have one question. I have to make filters for json response after specification and should do the same as you wrote but instead of / to be . and instead () be [] , simply I need to change characters. Is it possible to do this without changing your code?
Best regards,
Balsa
The below exception is being thrown when using the PartialResponse.AspNetCore.Mvc.Formatters.Json package in asp.net core 2.0
MissingMethodException: Method not found: 'Microsoft.Net.Http.Headers.MediaTypeHeaderValue Microsoft.Net.Http.Headers.MediaTypeHeaderValue.Parse(System.String)'
PartialResponse.AspNetCore.Mvc.Formatters.Json.Internal.MvcPartialJsonMvcOptionsSetup.Configure(MvcOptions options)
Microsoft.Extensions.Options.OptionsFactory.Create(string name)
Microsoft.Extensions.Options.OptionsManager+<>c__DisplayClass5_0.b__0()
System.Lazy.ViaFactory(LazyThreadSafetyMode mode)
System.Lazy.ExecutionAndPublication(LazyHelper executionAndPublication, bool useDefaultConstructor)
System.Lazy.CreateValue()
Microsoft.Extensions.Options.OptionsCache.GetOrAdd(string name, Func createOptions)
Microsoft.Extensions.Options.OptionsManager.Get(string name)
Microsoft.Extensions.Options.OptionsManager.get_Value()
Microsoft.AspNetCore.Mvc.Internal.DefaultApplicationModelProvider..ctor(IOptions mvcOptionsAccessor)
System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Hi,
So my problem is when my web api returns 400 Bad request code (one of parameter is invalid). In this case I return message in response with description of error. But PartialResponse cut this field (in mu case field is called 'Message').
As a workaround I can specify Message field in 'fields' parameter of request, but it isn't pretty from code perspective.
Is there any possibility to configure PartialResponse to skip deletion of fields in such cases?
In my WebApi projects I would like to build SQL Queries that return only the partial response fields.
Is it possible to make the GetPartialResponseFields "public", so that I can use the fields in the returned collection?
I am trying to set default fields by setting default value of fields parameter, see below code, this code not working and ignoring it and returning all fields.
`[Route("")]
[HttpGet]
public HttpResponseMessage GetAllLoginThemes(string Key, string Secret, string fields = "Data(Name,Title,IsPaid)")
{
}`
You have a feature branch feature/aspnetcore. When are you planning on releasing this as a stable package? Or are you planning on releasing a pre-release package? This is perfect for what I need but I need a AspNetCore nuget package. Thanks
Hi,
I try to use the nugget package but after install and config with :
GlobalConfiguration.Configuration.Filters.Add(new PartialJsonActionFilter()); GlobalConfiguration.Configuration.Formatters.Clear(); GlobalConfiguration.Configuration.Formatters.Add(new PartialJsonMediaTypeFormatter() { IgnoreCase = true });
I return response with :
HttpResponseMessage ReturnResult<T>(HttpStatusCode httpStatusCode, T result) { var response = new HttpResponseMessage(httpStatusCode); response.Content = new ObjectContent<T>(result, new PartialJsonMediaTypeFormatter()); return response; }
and in url I call :
{{domain}}/api/driversapp?fields=Id
I have all data and not just the Id.
Any idea?
Thanks,
Hi, thanks for making this available! I'm using this in an HTTPPOST-only API and even though I see the querystring coming in (?fields=x,y,z) for example, the output is not filtered accordingly. Are there certain return types that are expected? I'm using ihttpactionresult on my methods.
I added the lines to global.asax as specified:
protected void Application_Start() { GlobalConfiguration.Configure(WebApiConfig.Register); GlobalConfiguration.Configuration.Formatters.Clear(); GlobalConfiguration.Configuration.Formatters.Add(new PartialJsonMediaTypeFormatter() { IgnoreCase = true }); }
Each method was originally coded to flatten a DTO into JSON as follows:
return Json(resp)
where resp is whatever DTO is appropriate for the method.
Can anyone suggest what I am missing?
Hi congrats for the great work,
so my problem is in my web api where all my request respond the following structure
{
totalCount:12,
data[....]
}
When the are no data
{
totalCount:0,
data[]
}
and apply fields=totalcount,data(field1,field2)
then i get a response with data[] removed
{
totalCount:0
}
thats a problem because it cannot be mapped properly on the client
According to https://developers.google.com/drive/api/v3/performance#partial requests to API responses that use "data" wrappers, where the response is nested within a data object that looks like data: { ... }, one should not include "data" in the fields specification.
So instead of "fields=data(a,b)" it should be specified like "fields=a,b".
In this case the filtering is only applied to the data property; any other properties of the wrapper object should not be filtered. Eg. { "success": true, "data": { ... } }
To not break the old versions this could be implemented as a property like with IgnoreCase on PartialJsonMediaTypeFormatter.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.