question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

question: @Body() empty with @Controller?

See original GitHub issue

Hi guys,

Whenever I use @Controller I seems to not receive JSON body content. It works when I use @Jsoncontroller, am I missing anything?

I use createExpressApp, I tried version 0.8 and 0.9 and express 4 and 3. @Controller always return {} while Jsoncontroller works.

@Controller('/templates')
export class TemplateController {
    @Post('/:name')
    public getTemplate(@Param('name') templateName: string, @Body() body: any): string {
        return this.templateService.render(templateName, body)
    }
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
antowkabondcommented, Jun 30, 2020

@posabsolute @ivanproskuryakov You have to add bodyParser

import express from “express”; import bodyParser from ‘body-parser’;

server.use(bodyParser.json()); server.use(bodyParser.urlencoded({extended: true}));

useExpressServer(server, {});

server.listen(PORT, function () { console.log(‘Example app listening on port 3000’) });

1reaction
azaslonovcommented, Jul 31, 2020

Hi @antowkabond, thanks, this is working indeed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Body is empty during POST method to server controller
I'm requesting a send response from my client containing an object, but on my back-end, when i console.log(req.body), the server shows it being ......
Read more >
JAVA - Getting empty MockHttpServletResponse: | Chegg.com
Question : JAVA - Getting empty MockHttpServletResponse: body..However it's 200. package com.controller; import javax.validation.constraints.NotBlank; import ...
Read more >
Component Body is empty after init event but not from Chrome ...
And this is what happens from c:carouselComponent controller in init handler : onInit: function(component, event, helper) { var body = component ...
Read more >
Response with empty body - is this a problem? - jQuery Forum
Hi, I am using Chrome to send a request from the browser to the Micrium HTTP server, which is successfully received by the...
Read more >
ViewModel data is empty on form submit when using ...
public IPagedList PagingMetaData { get; set; }; }; }. Controller code:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found