forked from corda/corda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ApiUtils - a library for managing api lifecycles with less boilerplate. Added default values to http api and improved the api utils. Fixed spacing and comments. Removed withName and added a bad request response to handle error cases. Replaced use of 400 error with a 404 and error message as per HTTP spec.
- Loading branch information
Showing
4 changed files
with
32 additions
and
202 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
27 changes: 27 additions & 0 deletions
27
core/src/main/kotlin/com/r3corda/core/utilities/ApiUtils.kt
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,27 @@ | ||
package com.r3corda.core.utilities | ||
|
||
import com.r3corda.core.crypto.Party | ||
import com.r3corda.core.crypto.parsePublicKeyBase58 | ||
import com.r3corda.core.node.ServiceHub | ||
import javax.ws.rs.core.Response | ||
|
||
/** | ||
* Utility functions to reduce boilerplate when developing HTTP APIs | ||
*/ | ||
class ApiUtils(val services: ServiceHub) { | ||
private val defaultNotFound = { msg: String -> Response.status(Response.Status.NOT_FOUND).entity(msg).build() } | ||
|
||
/** | ||
* Get a party and then execute the passed function with the party public key as a parameter. | ||
* Usage: withParty(key) { doSomethingWith(it) } | ||
*/ | ||
fun withParty(partyKeyStr: String, notFound: (String) -> Response = defaultNotFound, found: (Party) -> Response): Response { | ||
return try { | ||
val partyKey = parsePublicKeyBase58(partyKeyStr) | ||
val party = services.identityService.partyFromKey(partyKey) | ||
if(party == null) notFound("Unknown party") else found(party) | ||
} catch (e: IllegalArgumentException) { | ||
notFound("Invalid base58 key passed for party key") | ||
} | ||
} | ||
} |
200 changes: 0 additions & 200 deletions
200
src/main/kotlin/com/r3corda/demos/attachment/AttachmentDemo.kt
This file was deleted.
Oops, something went wrong.
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