Can't access a requests body inside api controller

System Information
  • Strapi Version: 4.0.7
  • Operating System:
  • Database: postgres
  • Node Version:
  • NPM Version:
  • Yarn Version:

I made an api can’t figure out how to access the body from my request inside my controller. There seems to be URI encoded body data somewhere inside the context, but it never seems to materialize into any sort of readable JSON data.

EDIT:

I was able to access the data by reading the stream like in this post, the result is an URI encoded query string that I then need to convert to JSON.

Surely this can’t be the intended way to access the body data, is there a better way?

Thanks

// src/api/xxx/controllers/xxx.js
module.exports = {
	start: async (ctx, next) => {
		try {
			await next()
			console.log(ctx.req.body)
			return ctx.req.body
			// undefined
		} catch (err) {
			ctx.body = err;
		}
	}
}

// src/api/xxx/routes/xxx.js
module.exports = {
  routes: [
    {
     method: 'GET',
     path: '/xxx',
     handler: 'xxx.start',
     config: {
       policies: [],
       middlewares: [],
     },
    },
  ],
};