Skip to content
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

Add DeleteGraphDef to graph-defs API #157

Merged
merged 1 commit into from
May 29, 2024
Merged

Conversation

roodni
Copy link
Contributor

@roodni roodni commented May 28, 2024


// DeleteGraphDef deletes a graph definition.
func (c *Client) DeleteGraphDef(name string) error {
_, err := requestJSON[any](c, http.MethodDelete, "/api/v0/graph-defs/delete", map[string]string{"name": name})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, this is the first DELETE API requiring the request body :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes :) We did so, although it is somewhat unusual, because while it is common to DELETE a resource by including an ID or similar in the URL path, I was hesitant to include a part of the metric name in the path as an ID.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could use the percent encoded name in path like /api/v0/hosts-by-custom-identifier/{custom-identifier}, but I'm not strongly against using the request body. My another concern is the verb in the paths is unusual in Mackerel APIs. For example POST /api/v0/graph-defs and DELETE /api/v0/graph-defs (or DELETE /api/v0/graph-defs/{metric-name}) are more aligned to other APIs? I remember some (Google?) API design guides recommend POST /{resource-name}/:{verb}, but consistency in the API set is more important anyway. The POST /api/v0/graph-defs/create is an old(est?) API so you'll need to keep the alias forever (GET /api/v0/hosts.json is still there I believe).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We considered the idea of putting the name parameter in the URL path, but we thought it was unnatural as our internal data model (sorry for the internal talk). We are still puzzled, but we decided to put it in the request body. I hope you will forgive me.

Regarding the second topic, you are absolutely right about the /delete in the URL path. It should be DELETE /api/v0/graph-defs. We will fix it, so please wait.

@roodni roodni merged commit f193f02 into master May 29, 2024
10 checks passed
@roodni roodni deleted the api-delete-host-graph-def branch May 29, 2024 06:31
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.

4 participants