Skip to content
This repository has been archived by the owner on Mar 23, 2021. It is now read-only.

endocrimes/Resource

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Resource

Resource is a library for building API's with Frank, and other Nest Project web frameworks.

Example

struct Repository: Resource {
    let name = "Resource"
    let description = "Library for building REST API's with Frank"
}

if requested as JSON would return:

{
    "name": "Resource",
    "description": "Library for building REST API's with Frank"
}

Resource will also embed any resources returned in the relations() dictionary.

For example:

public struct User: Resource {
	let prettyName = "Danielle Lancashire"
	let username = "endocrimes"
	let favouriteRepository = Repository()

	public func attributes() -> [String : Any] {
		return ["pretty_name": prettyName, "username": username]
	}

	public func relations() -> [String : [Resource]] {
		return ["favourite_repository": [favouriteRepository]]
	}
}

if requested as JSON would return:

{
	"pretty_name": "Danielle Lancashire",
	"username": "endocrimes",
	"embed": {
		"favourite_repository": {
			"name": "Resource",
			"description": "Library for building REST API's with Frank"
		}
	}
}

Content Types

Default

Resource comes with support for:

  • JSON (application/json)

Custom

You can provide custom content types by overriding the encoders function on a resource.

Coming Soon

  • [] Better support for content negotiation