-
Notifications
You must be signed in to change notification settings - Fork 477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API consistency: OK, response only has "data", remove okResponseGsonObject #3433
Conversation
Whenever the native API returns an OK response, it returns a JSON object with the key "data" and lots of detail within. "data" is the only key returned so I'm moving "message" to be within the "data" object to be consistent with the rest of the native API. I'm also removing the `okResponseGsonObject` method from the AbstractApiBean for consistency. We don't want it to be cluttered with Gson, Jackson or other methods.
@scolapasta @pdurbin, question API consistency for the Currently API response for errors:
{
"status": "ERROR",
"message": "This file has a duplicate already in the dataset: dataverseproject-1.png"
} Successful API responses
{
"status": "OK",
"data": {
"message": "File successfully added!",
"files": [
{
"dataFile": {
"originalFormatLabel": "UNKNOWN",
"contentType": "text/csv",
"description": "Blue skies!",
"rootDataFileId": -1,
"checksum": {
"type": "MD5",
"value": "f8a112f69bd4419466db2efca0df7e55"
},
"tags": [],
"filename": "add_0001-15.csv",
"filesize": 105,
"md5": "f8a112f69bd4419466db2efca0df7e55",
"id": 417,
"categories": [
"Data",
"Glue",
"Foo",
"Blue",
"Zoo"
],
"storageIdentifier": "1580289e73a-09fd5635e516"
},
"datasetVersionId": 191,
"version": 1,
"description": "Blue skies!",
"label": "add_0001-15.csv"
}
]
}
}
|
@raprasad that's right. "message" is returned for errors. Here are the rules:
I didn't write the code. @michbarsinai did. I'm just trying to keep the API consistent. |
@pdurbin : I kept the |
Closing. Covered in 1612 branch. |
@sbarbosadataverse @raprasad I slept on it and it and while I still want consistency, I think we should consider creating a GitHub issue called "Have consistent location of success messages in the API". Think about building a GUI in React of Angluar on top of the Dataverse API. Users are clicking things and you want to display success messages to them. This would be the equivalent of our
It would be hard to build a UI in React or Angular from the JSON output above for creating a dataset. Yes, let's talk to @michbarsinai and get his thoughts. |
Hi Guys. Sorry to jump so late on this issue. I think the point the discussion is at (as far as I understand it) is correct: on success, we return the payload in The differentiation between This design where a value at a known field tells the client how to access the rest of the object is not new or unique to us. It's the main reason C has Note that the HTTP protocol gives us another place to put the result - the response code. This is why we have response methods like This design breaks the DIY principle in that the Lastly, I don't see any problem with writing UI based on the API as they are now, regardless of the technology being used. HTTP clients maintain state between request and response, and so when the client gets an answer it should know what the question was. |
@michbarsinai : so you agree(?) that we can move {
"status": "OK (or created)",
"message": "File successfully added!",
"data": {
"file data" : "lots of info"
}
} |
Is message in data now? it should be moved out. It's a semantic error to keep it in (again, especially in cases where the payload contains a legitimate message field). As for user-friendly messages, it's API. It should not be UI-friednly on the successful path, since you're making an assumption on the UI itself. For one thing, the below message can't be localized. Or an app might decide to show a green checkmark near the file icon instead of a message. I think we're better off not having messages when we have payload. Ideally we'd also do the errors in a UI-independent way, but it's much harder. And the HTTP response is indeed UI independent.
|
Good. Agreed. |
(whew) yes, it was in some of the original api code this way: protected Response ok( String msg ) {
return Response.ok().entity(Json.createObjectBuilder()
.add("status", STATUS_OK)
.add("data", Json.createObjectBuilder().add("message",msg)).build() )
.type(MediaType.APPLICATION_JSON)
.build();
} |
@michbarsinai @raprasad it sounds like you're talking about changing the 49 occurrences of "message" being nested with "data" in the "OK" case. Is it time to version the API? Backwards compatibility is important. Maybe I'm misunderstanding you. I'm glad we're doing pull requests and code review these days. 😄 |
@michbarsinai @scolapasta please code review this commit by @raprasad to make sure it's what we want before it gets merged: 0540ce0 |
…ard compat. for now. (need to swagger this stuff)
It's a simple rule, really. If the message is an OK one (2XX) payload goes in the In the general case, API clients need not rely on textual messages from the server to communicate a request result to the user. I see where this pull request comes from, but IMHO it should not be merged. abstract class DataverseResponse {
int httpCode;
}
class OK extends DataverseResponse {
Map<KEY,Object> data;
}
class Error extends DataverseResposne {
String message;
} As for versioning the API, I think we have more urgent things to do now. If we were to do it, adding details to error messages might be a nice thing to add. We currently use the message field there since software does not have to be perfect, but it has to be delivered :-). |
Whenever the native API returns an OK response, it returns a JSON object
with the key "data" and lots of detail within. "data" is the only key
returned so I'm moving "message" to be within the "data" object to be
consistent with the rest of the native API.
I'm also removing the
okResponseGsonObject
method from theAbstractApiBean for consistency. We don't want it to be cluttered with
Gson, Jackson or other methods.