Instawork / hyperview

Server-driven mobile apps with React Native

Home Page:https://hyperview.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Verb http methods

rickheere opened this issue · comments

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!

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.

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.

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

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

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.

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

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.

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