# Accept only Content-Type: 'application/json' for a HTTP event

**URL:** <https://forum.serverless.com/t/accept-only-content-type-application-json-for-a-http-event/11411>\
**Category:** Serverless Framework\
**Tags:** lambda, api-gateway\
**Created:** [May 11, 2020, 10:30am UTC](https://forum.serverless.com/t/accept-only-content-type-application-json-for-a-http-event/11411 "2020-05-11T10:30:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sajithneyo](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/sajithneyo/32/4231_2.png) [@sajithneyo](https://forum.serverless.com/u/sajithneyo)\
**Post date:** [May 11, 2020, 10:30am UTC](https://forum.serverless.com/t/accept-only-content-type-application-json-for-a-http-event/11411/1 "2020-05-11T10:30:17Z")

</div>

Hi,

Even though I include a validation schema other types are accepted by the API Gateway after deploying to AWS. For example plain texts are accepted. Of course error handling can be done for that. But is there any way to accept only a JSON data to the API. If so, how can I include it in the serverless.yml. I checked the documentation and found Lambda Integration ([https://www.serverless.com/framework/docs/providers/aws/events/apigateway/#lambda-integration](https://www.serverless.com/framework/docs/providers/aws/events/apigateway/#lambda-integration)). But how can I add accept header in serverless.yml?

Thank you

---

<div class="post-metadata">

**Author:** ![gaiachik](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/gaiachik/32/4322_2.png) [@gaiachik](https://forum.serverless.com/u/gaiachik)\
**Post date:** [June 10, 2020, 8:00am UTC](https://forum.serverless.com/t/accept-only-content-type-application-json-for-a-http-event/11411/2 "2020-06-10T08:00:47Z")

</div>

I am also looking for the answer to this! Did you get anywhere with it?  
Thanks!

---

<div class="post-metadata">

**Author:** ![Karthi96](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/karthi96/32/4326_2.png) [@Karthi96](https://forum.serverless.com/u/Karthi96)\
**Post date:** [June 11, 2020, 4:35pm UTC](https://forum.serverless.com/t/accept-only-content-type-application-json-for-a-http-event/11411/3 "2020-06-11T16:35:26Z")

</div>

Hi @sajithneyo @gaiachik,

Not sure whether i understood your requirement correctly. Correct me if i’m wrong, your requirement is accept only of content-Type application/json and how to achieve the same using serverless correct?

If i understood correctly means,

> ```
> service: Test-API
> 
> ```
> 
> provider:  
> name: aws  
> runtime: nodejs10.x  
> description: Test API for content-Type # optional, Description to publish to AWS  
> region: us-east-1  
> stage: Test-dev
> 
> functions:  
> GetCart:  
> handler: handler.hello  
> events:  
> - http:  
> path: /test1  
> method: get  
> authorizer: aws\_iam  
> integration: http  
> cors: false  
> request:  
> uri: ‘[http://karthibalu.simplesite.com](http://karthibalu.simplesite.com)’  
> passThrough: NEVER  
> template:  
> application/json: ‘{}’  
> parameters:  
> headers:  
> X-Ep-User-Roles: false  
> X-Ep-User-Scopes: false  
> X-Ep-User-Traits: false  
> X-Requested-With: false  
> X-Request-Id: false  
> X-Ep-User-Id: false  
> response:  
> statusCodes:  
> 200:  
> pattern: ‘’  
> headers:  
> Strict-Transport-Security: “‘max-age=31536000’”  
> Access-Control-Expose-Headers: “‘cLocation’”  
> Access-Control-Allow-Origin: “‘Original Url’”  
> cLocation: integration.response.header.Location  
> 500:  
> pattern: ‘500’  
> headers:  
> Strict-Transport-Security: “‘max-age=31536000’”  
> Access-Control-Allow-Origin: “‘Original Url’”

Let me know if this suits the requirement. !!!

Thanks, Always welcome for needy.

---

<div class="post-metadata">

**Author:** ![gaiachik](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/gaiachik/32/4322_2.png) [@gaiachik](https://forum.serverless.com/u/gaiachik)\
**Post date:** [June 11, 2020, 6:02pm UTC](https://forum.serverless.com/t/accept-only-content-type-application-json-for-a-http-event/11411/4 "2020-06-11T18:02:15Z")

</div>

Hello (and thank you)  
Yes. I realized that actually my question was different, because i am using lambda-proxy integration. I realized later that you can do it with the lambda one and NEVER as option for pass through.  
What I’ve done right now with lambda-proxy integration feels hacky, i.e. i just check the headers in the handler and return a 400 if they don’t match.  
I was hoping to find a way to do it without using lambda integration, but i could not find any info on how to do it with lambda-proxy. Maybe it’s not a possible setting.  
I did open a separate topic for my question (in case you know the answer to that, too! 🙂 [Reject requests based on content-type header, lambda-proxy](http://forum.serverless.com/t/reject-requests-based-on-content-type-header-lambda-proxy/11736)

Thank you  
Gaia
