Skip to content

Conversation

@matthewhanson
Copy link
Member

No description provided.

Sean Patrick Murphy and others added 30 commits April 21, 2020 15:03
# Background

My overall goal was to change from a:

`POST /collections/<collectionId>/items/<itemId>/edit`

to

`PATCH /collections/<collectionId>/items/<itemId>`

Which was more RESTful and also conforms to the stac-api's Transaction specification: https://github.com/radiantearth/stac-api-spec/tree/master/extensions/transaction

An /edit path is more traditionally used to render a HTML form which eventually will post to a PUT/PATCH endpoint.

# What's Includes

I also adjusted aspects of areas I was touching directly:

- The above route change
- Ability to easily toggle whether Transaction extension endpoints are available
- Simple HTTP constant utils introduced
- Fixed a bug where we required a blank `properties` param even if not are being modified

# Explanation of changes

We have a DIY routing approach inside api.js. Previously it was working with paths only, so I added support for also recognizing the HTTP method when it comes to determining different behavior for identical paths.

I found myself working in several cases with inline string literals for HTTP methods. I'd rather use constants and symbols, so I made a really minimal util to provide this.

I introduced a way to easily toggle the transaction endpoints, driven by an environment variable. I also instructions to the README regarding this.

Finally, I fixed an issue that required callers to specify a blank `properties` param even if none are being modified. The problem before was the edit endpoint trying to set an `updatedAt` date inside this object, and if it was nil there'd be an exception.

# Testing

The new behavior is triggered during a call to:

`PATCH /collections/<collectionId>/items/<itemId>`

Which is primarily used to change the collection of an item. Sample bodies include:

```
{
  "collection": "new-collection"
}
```

or with other properties

```
{
  "collection": "new-collection",
  "properties": {
    "some-other-property": true
  }
}
```

- `properties` will always get an `updated` attribute automatically assigned to the current date.
  - If other attributes are alongside in this object, it's merged with them.
  - If the input tries to provide updated as one of those attributes, ours is overwritten.
  - If no properties object is provided, we default to one with only `updated`

-----

It's probably also worth testing other http methods on this same route, such as:

`GET /collections/<collectionId>/items/<itemId>`

# Toggling the Transactions extensions

See the note in README, but essentially this is driven by a boolean ENV setting in serverless.yml.  Previously we relied on commenting code, and moreover a code commit to change it.
Improve partial item editing / enabling of Transactions extensions
@matthewhanson matthewhanson merged commit 008f49f into master Aug 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants