You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This library provides support for ASP.NET Web API using the [Collection+JSON] (http://amundsen.com/media-types/collection/) hypermedia mediatype authored by [Mike Amundsen] (http://twitter.com/mamund).
4
4
5
5
## Features
6
6
7
7
* A set of models for fully representing a Collection+Json document.
8
+
* Support for extensions
8
9
* CollectionJsonFormatter which handles Collection+Json representations.
9
10
* CollectionJsonController which is a drop-in API controller that is designed to make it easy to support Collection+Json. It wires up the formatter for you / removes a lot of cruft.
10
11
* A set of adapter contracts for reading and writing Collection+json documents.
@@ -22,57 +23,140 @@ CollectionJson ships with several nuget packages that are factored for client an
22
23
*[WebApiContrib.Formatting.CollectionJson.Server] (https://www.nuget.org/packages/WebApiContrib.Formatting.CollectionJson.Server) - Contains controllers for implementing the CJ protocol in ASP.NET Web API.
23
24
*[WebApiContrib.Formatting.CollectionJson] (https://www.nuget.org/packages.WebApiContrib.CollectionJson) - Meta package for backward compatability, pulls in WebApiContrib.Formatting.CollectioJson.Server.
24
25
25
-
## IReadDocument and Collection
26
-
This interfaces corresponds to the message format Collection+Json defines for returning Collection+Json results.
26
+
## Returning a read document from a server
27
+
To create a new read document instantiate a `Collection` instance. The `CollectionJsonFormatter` will write this out to the CollectionJson format.
This interface corresponds to the message format Collection+Json defines for creating / updating items.
58
+
## Using extensions
59
+
The `Collection`, `Data`, `Item`, `Link` and `Query` classes are all extensible to allow for using CollectionJson extensions. There are two different methods for working with extensions.
55
60
61
+
### Using dynamic
62
+
Extensions can be set by casting to dynamic and setting arbitrary extension properties. Below is an example setting the Model extension.
Extensions can be retrieved by calling the GetValue method
78
+
```csharp
79
+
varmodel=item.GetValue<string>("Model");
71
80
```
72
81
73
-
## CollectionJsonController
82
+
## API
83
+
### IReadDocument / ReadDocument
84
+
A CollectionJson server returns an object implementing IReadDocument. The `CollectionJsonFormatter` casts the model to this interface to write out the payload. The concrete ReadDocument class implements this interface.
A CollectionJson server receives an object implementing IWriteDocument. The `CollectionJsonFormatter' casts the model to this interface to read in the template. The concrete WriteDocument class implements this interface.
Data | Contains the data elements for the template
146
+
147
+
148
+
### CollectionJsonController_Of_T
74
149
This controller is a drop in component that one can derive from to implement the Collection+Json CRUD protocol. It constrains to strictly returning and accepting the correct message formats based on the spec. It also handles concerns like status codes, auto-generating the location header etc.
@@ -126,7 +210,7 @@ public class FriendsController : CollectionJsonController<Friend>
126
210
127
211
An implementer overrides methods from the base. The controller abstracts away the CJ format, which is handled via a set of adapters.
128
212
129
-
# ICollectionJsonDocumentReader
213
+
###ICollectionJsonDocumentReader
130
214
131
215
The reader is responsible for taking a Collection+JSON write template and convering it into "some" model. The model can be anything from a primitive like a string to a complex object.
132
216
@@ -146,7 +230,7 @@ public class FriendDocumentReader : ICollectionJsonDocumentReader<Friend>
146
230
}
147
231
```
148
232
149
-
# ICollectionJsonDocumentWriter
233
+
###ICollectionJsonDocumentWriter
150
234
151
235
The writer is responsible for taking the model and writing it out as Collection+Json Document.
152
236
@@ -162,32 +246,8 @@ public class FriendDocumentWriter : ICollectionJsonDocumentWriter<Friend>
0 commit comments