Can "success" boolean in API responses be used to determine if an API call worked?

28 views
Skip to first unread message

matt.t...@pearson.com

unread,
Apr 14, 2015, 10:43:53 AM4/14/15
to thre...@googlegroups.com
The JSON responses from the API generally start with something like:

{
"message": "",
"success": true,
"responseCode": -1,
"object": [
{
[bunch of stuff removed]
}
}

Can the "success": true boolean be used to determine if the API call worked as expected.

I'm currently looking at the Upload Scan API call [1] but wonder if this can be used generally to determine success of an API call.

Bonus points if the message can be used to describe the reason for a failure of an API call.

Can you confirm this behavior for the Upload Scan API call and/or the ThreadFix generally.

Thanks!

[1] https://github.com/denimgroup/threadfix/wiki/ThreadFix-REST-Interface#upload-scan

-- Matt Tesauro

Mac Collins

unread,
Apr 14, 2015, 11:22:05 AM4/14/15
to thre...@googlegroups.com
Hi Matt,

That's the idea. We use this same format in the ThreadFix UI so that we
can use generic Angular controllers for most of the modals and still have
easily customizable error messages. Any Angular code that interacts with
the ThreadFix UI will have some code like this:

if (data.success) {
// close the modal, display success message, etc.
} else {
$scope.errorMessage = "Failure: " + data.message;
}


Other API clients can use similar logic. We standardized our JSON format
by returning a RestResponse object with a type parameter from most
@Controller methods, which then gets fed to Spring serialization. Our
threadfix-cli package deserializes the JSON back into the original
RestResponse<?> format, so instead of working with a generic JSON object
you can work with a RestResponse<Application>, RestResponse<Scan>, etc.
and take advantage of static typing.

While I'm on the subject, the threadfix-cli package is now available in
the Maven Central repositories:
http://mvnrepository.com/artifact/com.denimgroup.threadfix/threadfix-cli


Thanks,
Mac

On 4/14/15, 9:43 AM, "matt.t...@pearson.com" <matt.t...@pearson.com>
wrote:
>--
>You received this message because you are subscribed to the Google Groups
>"ThreadFix" group.
>To unsubscribe from this group and stop receiving emails from it, send an
>email to threadfix+...@googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

matt.t...@pearson.com

unread,
Apr 14, 2015, 3:44:23 PM4/14/15
to thre...@googlegroups.com
Perfect. This is just the info I needed.

Cheers!

-- Matt Tesauro

On Tuesday, April 14, 2015 at 10:22:05 AM UTC-5, Mac Collins wrote:
> Hi Matt,
>
> That's the idea. We use this same format in the ThreadFix UI so that we
> can use generic Angular controllers for most of the modals and still have
> easily customizable error messages. Any Angular code that interacts with
> the ThreadFix UI will have some code like this:
>
> if (data.success) {
> // close the modal, display success message, etc.
> } else {
> $scope.errorMessage = "Failure: " + data.message;
> }
>
>
> Other API clients can use similar logic. We standardized our JSON format
> by returning a RestResponse object with a type parameter from most
> @Controller methods, which then gets fed to Spring serialization. Our
> threadfix-cli package deserializes the JSON back into the original
> RestResponse<?> format, so instead of working with a generic JSON object
> you can work with a RestResponse<Application>, RestResponse<Scan>, etc.
> and take advantage of static typing.
>
> While I'm on the subject, the threadfix-cli package is now available in
> the Maven Central repositories:
> http://mvnrepository.com/artifact/com.denimgroup.threadfix/threadfix-cli
>
>
> Thanks,
> Mac
>
> On 4/14/15, 9:43 AM, "Matt Tesauro" <>
Reply all
Reply to author
Forward
0 new messages