Skip to content

Commit df52884

Browse files
Some new docs, release notes (#191)
* Extra docs for queries * Update changelog & readme
1 parent 1c4c175 commit df52884

3 files changed

Lines changed: 104 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
## `master` (upcoming 1.7)
22

3+
- [**BUGFIX**] Serialise complex objects correctly (#149 by @laurence79)
4+
- [**BUGFIX**] Do not require Accept header (#151 by @bjornharrtell)
5+
- [**FEATURE**] Optional links support (#153 by @bjornharrtell)
6+
- [**BUGFIX**] Fix regression missing 'data' key for relationships when using DisableDefaultIncluded (#155 by @bjornharrtell)
7+
- [**FEATURE**] Add support for metadata (#158)
8+
- [**BUGFIX**] Omit data for relationship objects not existing as property in the original model (#161 by @bjornharrtell)
9+
- [**FEATURE**] Pagination page size (#165 by @erikhejl, #170 by @sergey-litvinov-work)
10+
- [**FEATURE**] Configuration improvments (formatter can be only add at end of the collection, without deleting other formatters) (#168 by @tomasjurasek)
11+
- [**FEATURE**] Functionality to return list of HttpErrors instead of just one error (#172 by @sergey-litvinov-work)
12+
- [**FEATURE**] Added deserialization method to `JsonApiSerializer<T>` (#179 @madsphi)
13+
- [**FEATURE**] Provide ability to handle JsonApi parameters in WebApi action itself manually (#181 by @sergey-litvinov-work)
14+
- [**MAINTENANCE**] Upgrade xunit dependencies (#183 by @bjornharrtell)
15+
- [**BUGFIX**] Fix regression with omitted data (#184 by @bjornharrtell)
16+
- [**FEATURE**] Opt into JsonApi per webapi endpoint (#187, #189 by @barsh)
17+
- [**FEATURE**] Option to serialize attributes in camelCase (#190 by @barsh)
18+
319
## Version 1.6
420

521
- [**BUGFIX**] Support belongsTo relationships when data is null (#124 by @goo32)

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,13 @@ GET http://example.com/people/123
115115

116116
Deserialization works just like in normal Web API; you don't need
117117
to do anything special to make this work.
118+
119+
### Creating a new release
120+
121+
Follow the steps below to create a new release:
122+
123+
1. Create a branch called `release-v<version>` (e.g. `release-v1.5`)
124+
2. Increase the version number in `appveyor.yml` in `master`
125+
3. Push both changes and wait for the build
126+
4. Copy the release notes into the release description on Github
127+
5. Publish the new release

docs/content/7-queryable-endpoints.md

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public IQueryable<Person> GetPeople()
2525
}
2626
```
2727

28-
> **Note**: Saule only supports the `sort` and `filter` query parameters.
28+
> **Note**: Saule supports the `sort`, `include` (for relationships) and `filter`
29+
> query parameters.
2930
> The same attribute may support other queries in the future.
3031
3132
```
@@ -180,4 +181,79 @@ public static void Register(HttpConfiguration config)
180181

181182
config.ConfigureJsonApi(jsonApiConfig);
182183
}
183-
```
184+
```
185+
186+
## Disabling default includes
187+
188+
By default, Saule includes all available relationships in the response. If this is
189+
not what you want, you can disable this behavior using the `DisableDefaultIncludedAttribute`.
190+
When you add this attribute to an action method, it will only include relationships
191+
specifically requested by clients using the `include` query parameter.
192+
193+
Note that even if you do not use this attribute, if the client provides the `include` parameter,
194+
Saule will not include anything that was not requested. For example, if your `Person` model
195+
has `Job` and `Friends` relationships, and the client requests `include=friends`, `Job` will
196+
not be returned in the response.
197+
198+
## Manually handling queries
199+
200+
Saule can apply sorting, filtering, includes and pagination to responses
201+
automatically. If you would rather do this yourself, or if your setup is
202+
not compatible with Saules implementation, you can also manually apply the
203+
query parameters. In order to do this, you must use the `HandlesQueryAttribute`:
204+
205+
```csharp
206+
[ReturnsResource(typeof(PersonResource))]
207+
public class PeopleController : ApiController
208+
{
209+
[HttpGet]
210+
[HandlesQuery]
211+
[Paginated]
212+
[Route("people")]
213+
public IEnumerable<Person> GetPeople(QueryContext context)
214+
{
215+
IEnumerable<Person> data = GetSomePeople();
216+
217+
bool? hideLastName;
218+
// if we want to include car or job, then we return response as is as it already has them
219+
// otherwise we clear it
220+
bool includeCar = context.Include.Includes.Any(p => p.Name == nameof(Person.Car));
221+
bool includeJob = context.Include.Includes.Any(p => p.Name == nameof(Person.Job));
222+
223+
context.Filter.TryGetValue("HideLastName", out hideLastName);
224+
225+
if (hideLastName.GetValueOrDefault() || !includeCar)
226+
{
227+
foreach (var person in data)
228+
{
229+
if (hideLastName.GetValueOrDefault())
230+
{
231+
person.LastName = null;
232+
}
233+
234+
if (!includeCar)
235+
person.Car = null;
236+
237+
if (!includeJob)
238+
person.Job = null;
239+
}
240+
}
241+
242+
int? minAge;
243+
if (context.Filter.TryGetValue("MinAge", out minAge) && minAge.HasValue)
244+
{
245+
data = data.Where(person => person.Age >= minAge);
246+
}
247+
248+
if (context.Pagination.PerPage.HasValue)
249+
{
250+
data = data.Take(context.Pagination.PerPage.Value);
251+
}
252+
253+
return data;
254+
}
255+
}
256+
```
257+
258+
The `QueryContext` parameter value is provided by Saule and contains the query
259+
information requested by the client.

0 commit comments

Comments
 (0)