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

Elysia doesn't parse html body content for GET requests #342

Open
maxshay opened this issue Jun 4, 2024 · 0 comments
Open

Elysia doesn't parse html body content for GET requests #342

maxshay opened this issue Jun 4, 2024 · 0 comments

Comments

@maxshay
Copy link

maxshay commented Jun 4, 2024

What is the type of issue?

Documentation is incorrect, Documentation is confusing, Example code is not working

What is the issue?

Using the example code found at https://elysiajs.com/patterns/mvc.html#service:

import { Elysia, t } from "elysia";

abstract class Service {
  static fibo(number: number): number {
    if (number < 2) return number;

    return Service.fibo(number - 1) + Service.fibo(number - 2);
  }
}

const app = new Elysia()
  .get(
    "/fibo",
    ({ body }) => {
      console.log(body);
      return Service.fibo(body);
    },
    {
      body: t.Numeric(),
    }
  )
  .listen(3000);

And running with postman:
Screenshot 2024-06-03 at 7 42 20 PM

I get a validation error:

{
  "type": "validation",
  "on": "body",
  "property": "root",
  "message": "Expected union value",
  "expected": 0,
  "errors": [
    {
      "type": 62,
      "schema": {
        "anyOf": [
          {
            "format": "numeric",
            "default": 0,
            "type": "string"
          },
          {
            "type": "number"
          }
        ]
      },
      "path": "",
      "message": "Expected union value"
    }
  ]
}

Removing the validation check I log out undefined when printing: console.log(body); as well as get a {"name":"RangeError","message":"Maximum call stack size exceeded."} response.

I assume according to best practices you shouldn't send HTTP body with GET requests. Do the docs need to be updated with .post(...) or is there a way to allow Elysia to parse GET body content?

Related Issue: #313

Where did you find it?

https://elysiajs.com/patterns/mvc#service

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

1 participant