Trailing slash on API URLs is very, very confusing

Open
#200 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
python
Domain
api, backend

Research direction

Start by reproducing the POST and PATCH requests against /api/patches/$NUMBER and /api/patches/$NUMBER/. Compare the redirect responses, methods, and resulting patch state. Done means the API's individual-object URL behavior is consistent and documented or corrected so updates do not silently become no-ops.

Written by the indexing model from the issue text.

Description

enhancement help wanted

@stewart-ibm was complaining that his script to update patch states via the REST API wasn't working.

His script was POSTing the update to "/api/patches/$NUMBER", and receiving an HTTP 200 in response, but no update.

I did some digging and discovered that when you access "/api/patches/$NUMBER", you get back a 301 Moved Permanently to "/api/patches/$NUMBER/" (note trailing slash). It seems that when you do a POST and get a 301 in response, the behaviour is to try a GET on the redirected URL, rather than a POST.

Once I figured this out, I tried doing a POST on the correct URL with the trailing slash, got a 405 Method Not Allowed, and quickly realised the real problem was that we should have been doing a PATCH.

For good measure, I checked what happens when you send a PATCH without the trailing slash, you get a 301, my logs seem to indicate that the subsequent request to the 301 target URL is still a PATCH, yet for some reason the state doesn't update. Not sure why.

Anyway, the trailing slash thing is really confusing and I'm not sure if it's semantically appropriate for accessing an individual object.

Thoughts?

Dominant language
Python
Stars
317
Forks
91
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from getpatchwork/patchwork

All issues in getpatchwork/patchwork

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.