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

Use meta for response headers, contentType, statusCode...etc #35

Closed
4 tasks done
icebob opened this issue Mar 6, 2018 · 1 comment
Closed
4 tasks done

Use meta for response headers, contentType, statusCode...etc #35

icebob opened this issue Mar 6, 2018 · 1 comment

Comments

@icebob
Copy link
Member

icebob commented Mar 6, 2018

Since Moleculer v.012 ctx.meta comes back to the caller. It means requests send context meta information back to API Gateway, like response status code, response headers, response content type...etc.

Meta keys what API Gateway will process:

  • ctx.meta.$responseType - set Content-Type in response
  • ctx.meta.$responseHeaders - set custom response headers
  • ctx.meta.$responseStatus - set HTTP status code in response
  • ctx.meta.$location - redirect location when the $responseStatus is 3xx

Example

{
    exportData(ctx) {
        // Set meta for API GW
        ctx.meta.$responseStatus = 200;
        ctx.meta.$responseType = "text/csv; charset=utf-8";
        ctx.meta.$responseHeaders = {
            "Content-Disposition": 'attachment; filename=\"data.csv\"'
        }

        // Return data
        return this.getAllRows();
    }
}
@icebob
Copy link
Member Author

icebob commented Mar 21, 2018

Will be released in 0.7

@icebob icebob closed this as completed Mar 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant