Skip to content

Instantly share code, notes, and snippets.

@takkaria
Last active November 25, 2019 16:21
Show Gist options
  • Save takkaria/00f4ec6afc73e2cb2e95aa2065d20b59 to your computer and use it in GitHub Desktop.
Save takkaria/00f4ec6afc73e2cb2e95aa2065d20b59 to your computer and use it in GitHub Desktop.
@fawkesley
Copy link

Getting the gallery

added trailing slash:

GET /assessment/<x>/

Result:

{
    ...
    "images": {
        "featured": null || X,
        "list": [
            {
                "id": 3,
                "note": "...",
                "url": "...",
                "width": 350,
                "height": 600,
                "thumbnail_url": "..."
                "thumbnail_width": 350,
                "thumbnail_height": 600,
            }
        ]
    }
}

what's X under "featured" ? A flatter structure would make more sense to me:

{
    ...
    "images": [
        {
            "id": 3,
            "featured": true
            "note": "...",
            "url": "...",
            "width": 350,
            "height": 600,
            "thumbnail_url": "..."
            "thumbnail_width": 350,
            "thumbnail_height": 600,
        }
    ]
}

Changing the featured image

This one's tricky, I'm not sure the most suitable thing to do here!

PATCH /assessment/<x>/ (set_featured_image)

Request:

{ "images": { "featured": 7 } }

this request body doesn't feel quite right to me:

{ "images": { "featured": 7 } }




Uploading a new image

added trailing slash
changed description to upload_image rather than upload_images

POST /assessment/<x>/images/ (upload_image)

Request:
Contains single multipart-encoded file

Deleting one image

DELETE /assessment/<x>/images?ids=5 (delete_images)

Two things

  1. I think it's more consistent to use embed IDs in the URL rather than query string
  2. I'd suggest images having a global ID and omitting the assessment from the URL*

DELETE /images/:image_id/ (delete_image)

Deleting many images

Personally I'd just keep it simple and don't offer this

DELETE /assessment/<x>/images?ids=5,3,6,7 (delete_images)

@takkaria
Copy link
Author

Great, I've taken on everything you suggested! That's really useful, thanks.

I've changed the 'set featured image' functionality to be a separate endpoint - does it look better to you? I was umming and ahhing about this for a while on Friday. I thought it was more RESTful to have the featured image be PATCHable, but I think it would be messy to implement it with the flatter image data structure (which I agree does make more sense!)

@fawkesley
Copy link

Yeah that new endpoint for changing the featured image looks ideal!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment