totaljs / framework4

Total.js framework v4
https://www.totaljs.com
Other
99 stars 36 forks source link

Need help with REST #20

Closed MathiasKrill closed 3 years ago

MathiasKrill commented 3 years ago

Hi, i have problems receiving any REST call with POST or GET. I tried HTTP Listener, Receiver, and Route but never get any reaction.

Thats for example the Route: route_setting

I use Postman to test-call: http://127.0.0.1:8000/test1/ and get <title>400: Bad Request</title>

Do i need to add addional settings somewhere? Some mappings maybe?

petersirka commented 3 years ago

Hi @MathiasKrill, please check the app logs / terminal output. Is there some error?

MathiasKrill commented 3 years ago

Hi, i used the repo: i used is "https://github.com/totaljs/emptyproject-flow.git" version from same day. If you familar with docker, i did this in my docker file:

Steps to reproduce, Dockerfile:

FROM ubuntu:20.04 

RUN apt-get update && DEBIAN_FRONTEND="noninteractive" TZ="Europe/London" apt-get install -y npm 
RUN apt-get install -y build-essential
RUN apt install -y nodejs
RUN apt-get install -y git

WORKDIR /usr/src/app
RUN npm install total4

COPY package*.json ./
COPY . .

WORKDIR /usr/src/app/src/node_modules/
RUN git clone https://github.com/totaljs/emptyproject-flow.git
WORKDIR /usr/src/app/src/node_modules/emptyproject-flow/
CMD ["node","index.js"]

Build and start: docker build -t . total docker run -p 127.0.0.1:8000:8000 total

Enter in Browser http://127.0.0.1:8000/

Flow created: flow_20210426-0038.zip

The post-request i used:

curl --location --request POST 'http://127.0.0.1:8000/test1/' \
--header 'Content-Type: text/plain' \
--data-raw '{"message":"just a test"}'

Error: <!DOCTYPE html>

``` 400: Bad Request
400
Bad Request
Invalid "Content-Type"
petersirka commented 3 years ago

Hi @MathiasKrill, sorry for delay. I have tested your Flow and everything works correctly. I saw your POST command and it's wrong because the Total.js framework can't process text/plain data as data. You need to use raw flag in the route or change your content-type to text/json.

Thank you.

MathiasKrill commented 3 years ago

Hey no problem for the delay . Thank you for looking for it. Will there be a change in future for the text/plain flag as data ?. Thank you for pointing out that :-)

petersirka commented 3 years ago

Thank you. No, no, you can use the raw flag only because Total.js framework parses the request payload/body according to its content-type. So plain/text can't be parsed because it's plain text. The raw flag will return a buffer that you can convert easily to text controller.body.toString('utf8')