Skip to content

Commit

Permalink
Merge pull request #44 from Financial-Times/fix/uppsf-859-remove-resp…
Browse files Browse the repository at this point in the history
…onse-body

Remove response body from POST, DELETE, PATCH endpoints
  • Loading branch information
mchompalova authored Nov 4, 2019
2 parents bbc057f + 1137dc2 commit 461aaa5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 122 deletions.
66 changes: 3 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,27 +127,7 @@ curl http://localhost:8080/drafts/content/{content-uuid}/annotations -X POST --d

A POST request on this endpoint adds an annotation to the editorially curated published annotations for a specific piece of content. To retrieve these annotations it calls [UPP Public Annotations API](https://github.com/Financial-Times/public-annotations-api) using the "lifecycle" parameter.
The new list of draft annotations will override any unpublished draft annotations for this piece of content.
If the operation is successful, the application returns the canonicalized input body with an HTTP 200 response code.

This is an example response body:
```
{
"annotations":[
{
"predicate": "http://www.ft.com/ontology/annotation/hasContributor",
"id": "http://www.ft.com/thing/5bd49568-6d7c-3c10-a5b0-2f3fd5974a6b",
},
{
"predicate": "http://www.ft.com/ontology/annotation/about",
"id": "http://www.ft.com/thing/d7de27f8-1633-3fcc-b308-c95a2ad7d1cd",
},
{
"predicate": "http://www.ft.com/ontology/annotation/hasDisplayTag",
"id": "http://www.ft.com/thing/d7de27f8-1633-3fcc-b308-c95a2ad7d1cd",
}
]
}
```
If the operation is successful, the application returns an HTTP 200 response code.

### PUT - Writing draft annotations to PAC

Expand Down Expand Up @@ -216,27 +196,7 @@ curl http://localhost:8080/drafts/content/{content-uuid}/annotations/{concept-uu
```

A DELETE request on this endpoint deletes all the annotations for a single concept from the editorially curated published annotations for a specific piece of content. To retrieve these specific annotations it calls [UPP Public Annotations API](https://github.com/Financial-Times/public-annotations-api) using the "lifecycle" parameter.
If the operation is successful, the application returns the canonicalized input body with an HTTP 200 response code.

This is an example response body:
```
{
"annotations":[
{
"predicate": "http://www.ft.com/ontology/annotation/hasContributor",
"id": "http://www.ft.com/thing/5bd49568-6d7c-3c10-a5b0-2f3fd5974a6b",
},
{
"predicate": "http://www.ft.com/ontology/annotation/about",
"id": "http://www.ft.com/thing/d7de27f8-1633-3fcc-b308-c95a2ad7d1cd",
},
{
"predicate": "http://www.ft.com/ontology/annotation/hasDisplayTag",
"id": "http://www.ft.com/thing/d7de27f8-1633-3fcc-b308-c95a2ad7d1cd",
}
]
}
```
If the operation is successful, the application returns an HTTP 200 response code.

### PATCH - Replacing draft editorial annotations

Expand All @@ -250,27 +210,7 @@ curl http://localhost:8080/drafts/content/{content-uuid}/annotations/{concept-uu

A PATCH request on this endpoint replaces all annotations for a single concept in the editorially curated published annotations for a specific piece of content. To retrieve these annotations it calls [UPP Public Annotations API](https://github.com/Financial-Times/public-annotations-api) using the "lifecycle" parameter.
The new list of draft annotations will override any unpublished draft annotations for this piece of content.
If the operation is successful, the application returns the canonicalized input body with an HTTP 200 response code.

This is an example response body:
```
{
"annotations":[
{
"predicate": "http://www.ft.com/ontology/annotation/hasContributor",
"id": "http://www.ft.com/thing/5bd49568-6d7c-3c10-a5b0-2f3fd5974a6b",
},
{
"predicate": "http://www.ft.com/ontology/annotation/about",
"id": "http://www.ft.com/thing/d7de27f8-1633-3fcc-b308-c95a2ad7d1cd",
},
{
"predicate": "http://www.ft.com/ontology/annotation/hasDisplayTag",
"id": "http://www.ft.com/thing/d7de27f8-1633-3fcc-b308-c95a2ad7d1cd",
}
]
}
```
If the operation is successful, the application returns an HTTP 200 response code.

## Healthchecks

Expand Down
27 changes: 3 additions & 24 deletions _ft/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ paths:
- Public API
consumes:
- application/json
produces:
- application/json
parameters:
- name: uuid
in: path
Expand Down Expand Up @@ -158,12 +156,7 @@ paths:
- predicate
responses:
200:
description: Returns a canonicalized array of annotations that have been successufully saved in PAC.
examples:
application/json:
annotations:
- id: http://api.ft.com/thing/d7113d1d-ed66-3adf-9910-1f62b2c40e6a
predicate: http://www.ft.com/ontology/annotation/about
description: The annotation was successfully saved to the cannonicalized list of annotations in PAC.
400:
description: Invalid content UUID, concept UUID or predicate supplied.
404:
Expand All @@ -176,8 +169,6 @@ paths:
description: Returns the draft annotations for the content after the delete operation.
tags:
- Public API
produces:
- application/json
parameters:
- name: uuid
in: path
Expand All @@ -193,12 +184,7 @@ paths:
x-example: 0667615f-499e-4fa6-8130-f3430450228d
responses:
200:
description: Returns the canonicalized array of annotations that have been successufully saved in PAC.
examples:
application/json:
annotations:
- id: http://api.ft.com/things/5507ab98-b747-3ebc-b816-11603b9009f4
predicate: http://www.ft.com/ontology/annotation/about
description: The annotation was successfully deleted from the cannonicalized list of annotations in PAC.
400:
description: Invalid content or concept UUID supplied
404:
Expand All @@ -212,8 +198,6 @@ paths:
- Public API
consumes:
- application/json
produces:
- application/json
parameters:
- name: uuid
in: path
Expand Down Expand Up @@ -249,12 +233,7 @@ paths:
- id
responses:
200:
description: Returns the canonicalized array of annotations that have been successfully saved in PAC.
examples:
application/json:
annotations:
- id: http://api.ft.com/things/d7113d1d-ed66-3adf-9910-1f62b2c40e6a
predicate: http://www.ft.com/ontology/annotation/mentions
description: The annotation was successfully replaced in the cannonicalized list of annotations in PAC.
400:
description: Invalid content or concept UUID supplied
404:
Expand Down
5 changes: 0 additions & 5 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,6 @@ func (h *Handler) saveAndReturnAnnotations(ctx context.Context, w http.ResponseW
}

w.Header().Set(annotations.DocumentHashHeader, newHash)
err = json.NewEncoder(w).Encode(newAnnotations)
if err != nil {
handleWriteErrors("Error encoding draft annotations response", err, writeLog, w, http.StatusInternalServerError)
return
}
}

// ReadAnnotations gets the annotations for a given content uuid.
Expand Down
32 changes: 2 additions & 30 deletions handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -838,12 +838,6 @@ func TestHappyDeleteAnnotations(t *testing.T) {
r.ServeHTTP(w, req)
resp := w.Result()
assert.Equal(t, http.StatusOK, resp.StatusCode)

actual := annotations.Annotations{}
err := json.NewDecoder(resp.Body).Decode(&actual)
assert.NoError(t, err)

assert.Equal(t, expectedCanonicalisedAnnotationsAfterDelete, actual)
assert.Equal(t, newHash, resp.Header.Get(annotations.DocumentHashHeader))

rw.AssertExpectations(t)
Expand Down Expand Up @@ -978,12 +972,6 @@ func TestHappyAddAnnotation(t *testing.T) {
r.ServeHTTP(w, req)
resp := w.Result()
assert.Equal(t, http.StatusOK, resp.StatusCode)

actual := annotations.Annotations{}
err := json.NewDecoder(resp.Body).Decode(&actual)
assert.NoError(t, err)

assert.Equal(t, actual, expectedCanonicalisedAnnotationsAfterAdditon)
assert.Equal(t, newHash, resp.Header.Get(annotations.DocumentHashHeader))

rw.AssertExpectations(t)
Expand Down Expand Up @@ -1025,12 +1013,6 @@ func TestHappyAddExistingAnnotation(t *testing.T) {
r.ServeHTTP(w, req)
resp := w.Result()
assert.Equal(t, http.StatusOK, resp.StatusCode)

actual := annotations.Annotations{}
err := json.NewDecoder(resp.Body).Decode(&actual)
assert.NoError(t, err)

assert.Equal(t, expectedCanonicalisedAnnotationsBody, actual)
assert.Equal(t, newHash, resp.Header.Get(annotations.DocumentHashHeader))

rw.AssertExpectations(t)
Expand Down Expand Up @@ -1071,12 +1053,6 @@ func TestHappyAddAnnotationWithExistingConceptIdDifferentPredicate(t *testing.T)
r.ServeHTTP(w, req)
resp := w.Result()
assert.Equal(t, http.StatusOK, resp.StatusCode)

actual := annotations.Annotations{}
err := json.NewDecoder(resp.Body).Decode(&actual)
assert.NoError(t, err)

assert.Equal(t, expectedCanonicalisedAnnotationsSameConceptId, actual)
assert.Equal(t, newHash, resp.Header.Get(annotations.DocumentHashHeader))

rw.AssertExpectations(t)
Expand Down Expand Up @@ -1319,6 +1295,7 @@ func TestHappyReplaceAnnotation(t *testing.T) {
r.ServeHTTP(w, req)
resp := w.Result()
assert.Equal(t, http.StatusOK, resp.StatusCode)
assert.Equal(t, newHash, resp.Header.Get(annotations.DocumentHashHeader))
}

func TestHappyReplaceAnnotationWithPredicate(t *testing.T) {
Expand Down Expand Up @@ -1383,6 +1360,7 @@ func TestHappyReplaceAnnotationWithPredicate(t *testing.T) {
r.ServeHTTP(w, req)
resp := w.Result()
assert.Equal(t, http.StatusOK, resp.StatusCode)
assert.Equal(t, newHash, resp.Header.Get(annotations.DocumentHashHeader))
}

func TestHappyReplaceExistingAnnotation(t *testing.T) {
Expand Down Expand Up @@ -1417,12 +1395,6 @@ func TestHappyReplaceExistingAnnotation(t *testing.T) {
r.ServeHTTP(w, req)
resp := w.Result()
assert.Equal(t, http.StatusOK, resp.StatusCode)

actual := annotations.Annotations{}
err := json.NewDecoder(resp.Body).Decode(&actual)
assert.NoError(t, err)

assert.Equal(t, expectedAnnotationsReplaceExisting, actual)
assert.Equal(t, newHash, resp.Header.Get(annotations.DocumentHashHeader))

rw.AssertExpectations(t)
Expand Down

0 comments on commit 461aaa5

Please sign in to comment.