Skip to content

Commit

Permalink
add simple readme
Browse files Browse the repository at this point in the history
  • Loading branch information
joukevandermaas committed Sep 12, 2015
1 parent 8c74ba6 commit 05e7c50
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 2 deletions.
88 changes: 86 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,86 @@
# saule
Json api library for ASP.Net Web API 2
# Saule
Saule is an Json Api (version 1.0) library for ASP.Net Web API 2.

To use Saule, you must define models that contain the information
about your domain:
```c#
public class PersonModel : ApiModel
{
public PersonModel()
{
Attribute("FirstName");
Attribute("LastName");
Attribute("Age");

BelongsTo("Job", typeof(CompanyModel));
HasMany("Friends", typeof(PersonModel));
}
}
public class CompanyModel : ApiModel
{
public CompanyModel()
{
Attribute("Name");
Attribute("NumberOfEmployees");
}
}
```

You can then use these to serialize any class into json api:
```c#
public class PersonController : ApiController
{
[HttpGet, Route("people/{id}")]
public ApiResponse<Person> GetPerson(string id)
{
return new Person().ToApiResponse(typeof(PersonModel));
}
}
```

```json
GET people/123

{
"data": {
"type": "person",
"id": "123",
"attributes": {
"first-name": "John",
"last-name": "Smith",
"age": 45
},
"relationships": {
"job": {
"links": {
"self": "people/123/relationships/job",
"related": "people/123/job"
},
"data" {
"type": "company",
"id": "345"
}
},
"friends": {
"links": {
"self": "people/123/relationships/friends",
"related": "people/123/friends"
}
}
}
},
"included": [
{
"type": "company",
"id": "345",
"attributes": {
"name": "Awesome Company",
"number-of-employees": 33
}
}
]
}
```

Deserialization works just like in normal Web Api; you don't need
to do anything special to make this work.
6 changes: 6 additions & 0 deletions Saule.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Saule", "Saule\Saule.csproj
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{BF3A993B-0AAC-419B-904C-E5B93E1C916D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9D2F8CA1-79B8-4492-907E-5BCF88429168}"
ProjectSection(SolutionItems) = preProject
LICENSE = LICENSE
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down

0 comments on commit 05e7c50

Please sign in to comment.