REST API response format based on some of the best practices
This file contains hidden or 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 elastic = require('elasticsearch'); | |
| var client = new elastic.Client({ host: 'localhost:9200' }); | |
| var index = 'myindex'; | |
| var type = 'document'; | |
| (function init() { | |
| Promise.resolve() | |
| .then(deleteIndex, handleError) |
This file contains hidden or 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
| /* | |
| Sort the roman kings names in acending order | |
| */ | |
| const romanNumerals = ['xl', 'l', 'xxx', 'xx', 'ix', 'x', 'iv', 'v', 'iii', 'ii', 'i']; | |
| const romanDecMap = { | |
| i: 1, | |
| ii: 2, | |
| iii: 3, | |
| iv: 4, |
This file contains hidden or 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
| namespace AnemicModelPart2 { | |
| class Bill { | |
| static create(title: any, billNo: any) { | |
| return new Bill(); | |
| } | |
| } | |
| class MyValidator { | |
| static validateBillNo(billNo: any): boolean { | |
| throw new Error('Method not implemented.'); |
This file contains hidden or 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 { Entity, PrimaryGeneratedColumn, Column } from "typeorm"; | |
| @Entity() | |
| export class Student { | |
| @PrimaryGeneratedColumn() | |
| student_id: number; | |
| @Column() | |
| studentFirstName: string; |
This file contains hidden or 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 * as express from 'express'; | |
| interface DecodedExpressRequest {} | |
| class CourseController { | |
| private models: any; | |
| constructor(models: any) { | |
| this.models = models; | |
| } |
This file contains hidden or 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
| You can implement it like this: | |
| Pass functions to endpoint decorator | |
| @httpPost('/', authenticateToken(), authorizeUser(['administrator'])) | |
| Function example | |
| export const authenticateToken = (/* PARAMS HERE */) => { | |
| return async (req: Request, res: Response, next: NextFunction) => { | |
| const authHeader = req.headers.authorization; |
This file contains hidden or 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
| specification oattern, #ddd, #typescript | |
| interface Specification<T> { | |
| isSatisfiedBy(candidate: T): boolean; | |
| and(other: Specification<T>): Specification<T>; | |
| or(other: Specification<T>): Specification<T>; | |
| not(): Specification<T>; | |
| } | |
| abstract class CompositeSpecification<T> implements Specification<T> { |
This file contains hidden or 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 csv | |
| import aiohttp | |
| import asyncio | |
| from concurrent.futures import ThreadPoolExecutor | |
| import time | |
| from datetime import datetime | |
| async def process_row(session, sem, executor, row): | |
| url = 'https://your_domain_url' | |
| payload = { |
Once upon a time…
I once took notes (almost sentence by sentence with not much editing) about the architectural design concepts - Command and Query Responsibility Segregation (CQRS) and Event Sourcing (ES) - from a presentation of Greg Young and published it as a gist (with the times when a given sentence was heard).
I then found other summaries of the talk and the gist has since been growing up. See the revisions to know the changes and where they came from (aka the sources).
It seems inevitable to throw Domain Driven Design (DDD) in to the mix.