Mirror of the Rel4tion website/wiki source, view at <http://rel4tion.org>

[[ 🗃 ^yEzqv rel4tion-wiki ]] :: [📥 Inbox] [📤 Outbox] [🐤 Followers] [🤝 Collaborators] [🛠 Commits]

Clone

HTTPS: git clone https://vervis.peers.community/repos/yEzqv

SSH: git clone USERNAME@vervis.peers.community:yEzqv

Branches

Tags

master :: projects / vervis / tickets /

2.mdwn

[[!template id=ticket class=task]]

[[!meta title=“Routes for operations”]]

Issue

Suppose I have route /#!Text for user pages, and routes /new and /delete for creating and deleting users respectively. How can /new make sure the user created isn’t named new or delete? If I hardcode the check, I’ll have the path pieces in 2 places and I’ll have to remember to keep them in sync manually, which is very error-prone.

Plan

I asked on IRC, haven’t asked in MLs yet. Ideas I see are:

Therefore:

REST

I read about [[!wikipedia REST]].

For a given user, HTTP verbs commonly work as follows. See the wikipedia link for more details.

There are also other HTTP methods, such as PATCH. When to use POST, when to use PUT? What if just few settings are changed? Let’s see some Yesod app examples. Looking in Hackage…

I’m reading [[!wikipedia “Patch verb”]] too. The idea is that:

PATCH seems to come from Ruby on Rails and involves extra complexity which Yesod doesn’t seem to have anything to do with. I can use the typical GET-PUT workflow. Here’s an initial suggestion:

What is the URL of the form though? When using JS, the form can be displayed anywhere, say the resource URL. But without eyecandy, the resource GET request returns a view, not a form with fields. So we need an additional, GET-only URL which returns a form with a button that PUTs it to the resource URL.

Do I still need to handle overlaps with this setup? Let’s see. Since Yesod picks the first route that matches in case of overlap, I could have something like this:

[[!format haskell """ /u PeopleR GET – Show list of people /u/!new AddPersonR GET – Supply new person registration form /u/#Text PersonR GET PUT – Show person or register person """]]

Is there a danger a user named “new” is created? While you can’t GET the details of such a user, you also can’t PUT them because the second route in the list will be matched, and it doesn’t have a POST handler. So you should get error 404. Hopefully.

I’m not done yet with reading about Yesod forms, but if forms must make a POST request and not PUT, I can support both PUT and POST, and simply make the POST handler be defined to the PUT handler.

Here’s a simple initial naming convention:

Ah, the Yesod book actually has a page called “RESTful Content”! Reading now.

Hmmm problem: PUT must use an existing resource state to modify. The target URL of a form is fixed. User creation needs to use a fixed route, not a PUT based on user ident. I asked on IRC and looked in Wikipedia again. Here’s a new scheme:

[[!format haskell """ /u PeopleR GET POST – Show list of people or create new person /u/!new AddPersonR GET – Supply new person registration form /u/#Text PersonR GET PUT – Show person or update person """]]

Result

Continue here…

[See repo JSON]