Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用nodejs和Lamda使restapi格式正确_Javascript_Node.js_Amazon Web Services_Aws Lambda - Fatal编程技术网

Javascript 使用nodejs和Lamda使restapi格式正确

Javascript 使用nodejs和Lamda使restapi格式正确,javascript,node.js,amazon-web-services,aws-lambda,Javascript,Node.js,Amazon Web Services,Aws Lambda,有没有一种方法可以格式化json rest api,使其不会缩小。我正在使用NodeJs/lambda和awsapi网关。我想要的是: 由此: 为此: 我的nodejs代码 它是APi网关/Lambda中的某个选项吗 我想JSON.stringifydata,null,2应该可以。2基本上是缩进空间。@Sole-cool。。请随意将其标记为答案,供其他人参考。是的,一旦时间框架过去,我会在我可以接受的地方进行标记 {"name":"Ultimate data","description":"Th

有没有一种方法可以格式化json rest api,使其不会缩小。我正在使用NodeJs/lambda和awsapi网关。我想要的是:

由此:

为此:

我的nodejs代码


它是APi网关/Lambda中的某个选项吗

我想JSON.stringifydata,null,2应该可以。2基本上是缩进空间。

@Sole-cool。。请随意将其标记为答案,供其他人参考。是的,一旦时间框架过去,我会在我可以接受的地方进行标记
{"name":"Ultimate data","description":"This is an example api build for get requests","number":"40"}
{
   "name":"Ultimate data",
   "description":"This is an example api build for get requests",
   "number":"40"
}
exports.handler = async (event) => {
   if (event.httpMethod === 'GET') {
       return getData(event);
   }
};

const getData = event => {
    let data = {
           name: 'Ultimate data',
           description: 'This is an example api build for get requests',
           number: '40'
    };
       return {
           statusCode: 200,
           body: JSON.stringify(data)
       };
};