GithubHelp home page GithubHelp logo

Can't read json raw request about goyave HOT 4 CLOSED

go-goyave avatar go-goyave commented on June 25, 2024
Can't read json raw request

from goyave.

Comments (4)

System-Glitch avatar System-Glitch commented on June 25, 2024 1

Hello and happy new year!

When sending JSON requests, don't forget the Content-Type: application/json header.

from goyave.

ridwankustanto avatar ridwankustanto commented on June 25, 2024

Ah, I missed it! Now I got the Request.Data works, thanks!

Aaand how about Request.Integer() and the others Accessors? still can't get the value, I tried add Content-Type: application/json or application/x-www-form-urlencoded, but still no luck.

from goyave.

System-Glitch avatar System-Glitch commented on June 25, 2024

When numbers are parsed from a JSON request, they are float64. So you can get it using the Numeric() accessor. You will get an integer if you validate the field using the integer rule.

Accessors won't convert your data, so if your request isn't validated, most of them won't work. From the docs:

You shouldn't use these accessors in middleware because they assume the data has been converted by the validation already.

Can you show me the raw request and a print of request.Data with a bool field please?

from goyave.

ridwankustanto avatar ridwankustanto commented on June 25, 2024

It was like this:

map[{
    "name": "John Doe",
    "tags": ["tag1", "tag2"],
    "is_active": true,
}:]

And I was trying to send the request using Content-Type: application/x-www-form-urlencoded. I just tried the implementation accessor (Numberic and Bool) with Content-Type: application/json and they both work.

Thank you!

from goyave.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.