-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add first routing extension, fix some links stuff
- Loading branch information
Koray Koska
committed
May 10, 2017
1 parent
da550db
commit 6f4fdfa
Showing
10 changed files
with
103 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// Droplet+VaporJsonApi.swift | ||
// VaporJsonApi | ||
// | ||
// Created by Koray Koska on 10/05/2017. | ||
// | ||
// | ||
|
||
import Vapor | ||
import HTTP | ||
|
||
public extension Droplet { | ||
|
||
public func jsonApiResource<C: JsonApiResourceController>(controller: C) { | ||
let resourceType = controller.resourceType.parse() | ||
// Get routes | ||
get(resourceType, handler: controller.getResources) | ||
get(resourceType, String.self, handler: controller.getResource) | ||
get(resourceType, String.self, String.self, handler: controller.getRelatedResource) | ||
|
||
// Post routes | ||
post(resourceType, handler: controller.postResource) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// Message+VaporJsonApi.swift | ||
// VaporJsonApi | ||
// | ||
// Created by Koray Koska on 10/05/2017. | ||
// | ||
// | ||
|
||
import Vapor | ||
import HTTP | ||
|
||
public extension Message { | ||
|
||
public var jsonApiJson: JSON? { | ||
get { | ||
if let existing = storage["jsonApiJson"] as? JSON { | ||
return existing | ||
} else if fulfillsJsonApiContentTypeResponsibilities() { | ||
guard case let .data(body) = body else { return nil } | ||
guard let jsonApiJson = try? JSON(bytes: body) else { return nil } | ||
storage["jsonApiJson"] = jsonApiJson | ||
return jsonApiJson | ||
} else { | ||
return nil | ||
} | ||
} | ||
set(jsonApiJson) { | ||
if let data = jsonApiJson { | ||
if let body = try? Body(data) { | ||
self.body = body | ||
headers[HeaderKey.contentType] = JsonApiConfig.mediaTypeValue | ||
} | ||
} | ||
storage["jsonApiJson"] = json | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters