Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joukevandermaas/saule
JSON API library for ASP.Net Web API 2.
https://github.com/joukevandermaas/saule
asp ember ember-data hacktoberfest json-api webapi webapi-2
Last synced: about 9 hours ago
JSON representation
JSON API library for ASP.Net Web API 2.
- Host: GitHub
- URL: https://github.com/joukevandermaas/saule
- Owner: joukevandermaas
- License: mit
- Created: 2015-09-12T14:05:55.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2023-09-20T10:50:41.000Z (about 1 year ago)
- Last Synced: 2024-10-14T11:28:18.272Z (about 1 month ago)
- Topics: asp, ember, ember-data, hacktoberfest, json-api, webapi, webapi-2
- Language: C#
- Homepage: https://joukevandermaas.github.io/saule
- Size: 734 KB
- Stars: 76
- Watchers: 9
- Forks: 37
- Open Issues: 24
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Saule
[![Build status](https://ci.appveyor.com/api/projects/status/uj3ddt85jaebjuh9/branch/master?svg=true)](https://ci.appveyor.com/project/JoukevanderMaas/saule/branch/master)Saule is a JSON API (version 1.0) library for ASP.Net Web API 2. Install Saule using NuGet:
```
Install-Package saule
```### [Visit the documentation website](http://joukevandermaas.github.io/saule)
To use Saule, you must define resources that contain the information
about your domain:
```c#
public class PersonResource : ApiResource
{
public PersonResource()
{
Attribute("FirstName");
Attribute("LastName");
Attribute("Age");BelongsTo("Job");
HasMany("Friends");
}
}
public class CompanyResource : ApiResource
{
public CompanyResource()
{
Attribute("Name");
Attribute("NumberOfEmployees");
}
}
```You can then use these to serialize any class into Json Api
(as long as your class has properties with the same names as
in your model):
```c#
public class PersonController : ApiController
{
[HttpGet]
[ReturnsResource(typeof(PersonResource))]
[Route("people/{id}")]
public JohnSmith GetPerson(string id)
{
return new JohnSmith();
}
}
``````json
GET http://example.com/people/123{
"data": {
"type": "person",
"id": "123",
"attributes": {
"first-name": "John",
"last-name": "Smith",
"age": 34
},
"relationships": {
"job": {
"links": {
"self": "http://example.com/people/123/relationships/job/",
"related": "http://example.com/people/123/job/"
},
"data": {
"type": "company",
"id": "456"
}
},
"friends": {
"links": {
"self": "http://example.com/people/123/relationships/friends/",
"related": "http://example.com/people/123/friends/"
},
"data": [
{
"type": "person",
"id": "789"
}
]
}
}
},
"included": [
{
"type": "company",
"id": "456",
"attributes": {
"name": "Awesome, Inc.",
"number-of-employees": 24
}
},
{
"type": "person",
"id": "789",
"attributes": {
"first-name": "Sara",
"last-name": "Jones",
"age": 38
}
}
],
"links": {
"self": "http://example.com/people/123"
}
}
```Deserialization works just like in normal Web API; you don't need
to do anything special to make this work.### Creating a new release
Follow the steps below to create a new release:
1. Create a branch called `release-v` (e.g. `release-v1.5`)
2. Increase the version number in `appveyor.yml` in `master`
3. Push both changes and wait for the build
4. Copy the release notes into the release description on Github
5. Publish the new release