This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#set($origin = $input.params(\"Origin\")) | |
#if($origin == \"\") | |
#set($origin = $input.params(\"origin\")) | |
#end | |
#if($origin.matches(\"https://my-origin-1.com\") || $origin.matches(\"https://my-origin-2.com\") | |
#set($context.responseOverride.header.Access-Control-Allow-Origin = $origin) | |
#end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Cors, Resource } from "@aws-cdk/aws-apigateway"; | |
// existing const resource: Resource | |
resource.addResource('MyCorsResource', { | |
defaultCorsPreflightOptions: { | |
allowOrigins: ['https://my-origin-1.com', 'https://my-origin-2.com'], | |
allowHeaders: Cors.DEFAULT_HEADERS.concat(['x-api-key']) | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LambdaProxyInput | |
{ | |
//...other properties | |
public Dictionary<string, string[]> multiValueQueryStringParameters { get; set; } | |
} | |
public object MyHandler(LambdaProxyInput input, ILambdaContext context) | |
{ | |
var myArrayValues = input.multiValueQueryStringParameters["MyQuerystringArray"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
..., | |
"multiValueQueryStringParameters": { | |
"parameter1": [ | |
"value1", | |
"value2" | |
], | |
"parameter2": [ | |
"value" | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// myApiResource: Resource defined | |
myApiResource.addMethod( | |
...http_method..., | |
{ | |
...lambda_integration_options... | |
requestTemplates: 'application/json': `{ | |
"MyQueryStringValue": "$input.params('MyQueryStringValue')" | |
#if ($input.params('MyQuerystringArray') != '') | |
,"MyQuerystringArray": $input.params('MyQuerystringArray') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyDto | |
{ | |
public string MyQueryStringValue { get; set; } | |
public string[] MyQuerystringArray { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var serviceCollection = new ServiceCollection(); | |
serviceCollection.AddTransient<IHttpService, HttpService>(); | |
serviceCollection.AddTransient<IService, LoggingService>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Processor | |
{ | |
// .. dependencies | |
void Process(MyInput input) | |
{ | |
if (ValidateInput(input)) | |
{ | |
new DatabaseConnection(...).ExecuteSql("..."); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EmailValidator | |
{ | |
private readonly IEnumerable<IEmailValidation> emailValidations; | |
/*...ctor...*/ | |
bool IsEmailValid(string email) => emailValidations | |
.Aggregate(true, (acc, src) => acc ? src.IsEmailValid(email) : acc); | |
} | |
interface IEmailValidation | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EmailValidator | |
{ | |
private readonly IEmailLengthValidation emailLengthValidation; | |
private readonly IEmailRegexValidation emailRegexValidation; | |
private readonly IEmailBlacklistValidation emailBlacklistValidation; | |
bool IsEmailValid(string email) | |
{ | |
if (!emailLengthValidation.IsEmailValid(email)) return false; | |
if (!emailRegexValidation.IsEmailValid(email)) return false; |