Skip to content

Instantly share code, notes, and snippets.

View mayank-kansal15's full-sized avatar

Mayank kansal mayank-kansal15

View GitHub Profile
@mayank-kansal15
mayank-kansal15 / logging-best-practices.md
Last active May 25, 2022 05:10
Logging best practices

What is logging?

Logging is the process of recording application actions and state to a secondary interface.

Why logging?

  • It tells what happened in the application at what time.
@mayank-kansal15
mayank-kansal15 / REST best practices
Last active May 16, 2022 07:36
This gist explains about the REST best practices and how to write pragmatic REST APIs.
# WHAT IS REST?
REST stands for Representational State Transfer. It’s a software architectural style for implementing web services. Web services implemented using the REST architectural style are known as the RESTful Web services.
In REST we transfer representation of a resource in a particular state at a point in time, that's why it is called REST.
For example: GET /v1/articles/123, transfer article 123 representation in JSON format in the state when API is hit.
REST use HTTP as a communication protocol, HTTP is a stateless protocol so should be REST. It means two REST APIs should be treated completely independent on server, both APIs should be authenticated and authorized, don't store anything from the first API call in server memory to be used by further API calls.
RESTful APIs are written for consumers. The name and structure of URIs should convey meaning to those consumers. Although your internal data models may map neatly to resources, it isn't necessarily a one-to-one mapping. The key here is to no
@mayank-kansal15
mayank-kansal15 / dynamoDBPagination.ts
Created September 8, 2017 00:15
This gist contain code to demonstrate how pagination can be done in DynamoDB.
function searchBlogByTitle(query: string, itemsPerPage: number, lastEvaluatedKey?: string): Promise<any> {
const FIXED_ID_FOR_SEARCH_GSI = "1233421345223";
let params: AWS.DynamoDB.DocumentClient.QueryInput = {
TableName: "Blog",
IndexName: "BlogSearch",
KeyConditionExpression: "fixedIdForSearchGSI = :pkv",
FilterExpression: "contains(titleInLowerCase, :titleV)",
ExpressionAttributeValues: {
":pkv": FIXED_ID_FOR_SEARCH_GSI,
":titleV": query.toLocaleLowerCase()