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

Verb http methods #493

Open
rickheere opened this issue Dec 17, 2022 · 8 comments
Open

Verb http methods #493

rickheere opened this issue Dec 17, 2022 · 8 comments

Comments

@rickheere
Copy link

Hi everyone, very exciting technologie. I have a website made with HTMX and I thought. Hyperview is a hyper media client and HTMX on top of html is so a hyper media client. If I can listen to the Accept header in my API and basted on it just return another response I almost get a mobile app for free! I can reuse all my routes, my database queries and all the rules. I followed the very well working "Getting started" and went to business.

Making a GET request on / worked as expected. Then doing a form POST did not work but I assume there is something I did wrong. Looking at the documentation for the verb it dawned on me there are only GET and POST and not any of the other http methods that I used building the website because HTMX supports those.

My question is, are there planes to implement these methods? Or am I missing something and there is a good reason not to implement those.

Very exiting to see hyper media work in mobile app!

@adamstep
Copy link
Contributor

Hi @rickheere, thanks for checking out the project. The approach you describe (looking at the Accept header to switch between HTML and Hyperview templates) works really well! We do that ourselves in some of our apps.

You are correct that we only support GET and POST right now, this was based on how HTML forms work. We didn't plan to add support for other HTTP methods, but it is something we could do if it makes it easier to use.

What language/framework are you using for your backend? Many frameworks support passing the method as a query param, eg POST /resource/123?method=delete. Happy to help here.

@rickheere
Copy link
Author

Thank you for the reply @adamstep. Adding the method as an parameter to get around my problem is a smart idea. I'm using nodejs with Express, I tested it out and I can just manually override the method value with some early middleware. There is even a middleware mentioned on the website Express.

@rickheere
Copy link
Author

rickheere commented Dec 19, 2022

I do however have another issue. If you want me to move it to a new ticket let me know. I menage to do a POST request but it looks like my setup is not able to parse the body. I'm using body-parser which is the go to library to parse the body. I set it up in a way to look for all typ's it supports and try to parse those, this is the default interface of the library

bodyParser()

I get an empty body object, this is the default response of the library if there is no body. The content-type coming in says it we are dealing with a "multipart/form-data; boundary=df2cf318-a7e6-4a73-b315-ff04b3619d0e". Looking around a bit it seems like people add the multer to be able to parse these. I configure it with the .none() option because the docs say this is for parsing fields and does not accept any file uploads.

const upload = multer()
...
...
  bodyParser(),
  upload.none(),

Now I get an error parsing the body.

[node] index-0  | Error: Unexpected end of form
[node] index-0  |     at Multipart._final (/home/rick/Repositories/ctoa-platform/node_modules/busboy/lib/types/multipart.js:588:17)
[node] index-0  |     at callFinal (node:internal/streams/writable:694:27)
[node] index-0  |     at prefinish (node:internal/streams/writable:723:7)
[node] index-0  |     at finishMaybe (node:internal/streams/writable:733:5)
[node] index-0  |     at Multipart.Writable.end (node:internal/streams/writable:631:5)
[node] index-0  |     at onend (node:internal/streams/readable:693:10)
[node] index-0  |     at processTicksAndRejections (node:internal/process/task_queues:78:11)

Doe you know where it goes wrong here?

photo_5836788018017581588_y

@rickheere
Copy link
Author

Alright I had some time to continue with the project again. I got the multipart request parsing to work with fine with connect-multiparty

@adamstep
Copy link
Contributor

adamstep commented Feb 9, 2023

Thanks for the update @rickheere. Glad it the request parsing works now. Multipart form data will help us support file uploads too like outlined in this issue: #300 . We are also considering adding more verb support so I'll leave this open for now.

@benjamin-kirkbride
Copy link

As a strong believer in REST (the OG REST, not the zeitgeist's bastardized REST), I would love to see all HTTP verbs supported.

@kimjisena
Copy link

Thanks for the update @rickheere. Glad it the request parsing works now. Multipart form data will help us support file uploads too like outlined in this issue: #300 . We are also considering adding more verb support so I'll leave this open for now.

This is good work. I'm just discovering Hyperview and I'm so hyped.

@adamwoolhether
Copy link

Just popping in to say that support of all verbs would be 🙌🏼

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

No branches or pull requests

5 participants