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
| const http = require('http'); // or https | |
| const defaultOptions = { | |
| host: 'example.com', | |
| port: 80, // or 443 for https | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| } | |
| } |
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
| const axios = require('axios').default; | |
| axios.interceptors.request.use(x => { | |
| // replace console with our logger of choice | |
| console.log(x); | |
| return x; | |
| }) | |
| axios.interceptors.response.use(x => { | |
| console.log(x) |
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
| const axios = require('axios').default; | |
| axios.interceptors.request.use(x => { | |
| const headers = { | |
| ...x.headers.common, | |
| ...x.headers[x.method], | |
| ...x.headers | |
| }; |
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 Product { | |
| @PrimaryGeneratedColumn() | |
| id: number; | |
| @Column() | |
| name: 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
| `{{ctx.periodStart}}` - ` {{ctx.periodEnd}}` | |
| _Total number of warnings_ : {{ctx.results.0.hits.total}} | |
| {{#ctx.results.0.hits.hits}} // Loop over hits | |
| *{{_source.message}}* | |
| _service_: `{{_source.module_name}}` | |
| _traceId_: `{{_source.trace_id}}` |
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
| const axios = require('axios').default; | |
| axios.interceptors.request.use( x => { | |
| // to avoid overwriting if another interceptor | |
| // already defined the same object (meta) | |
| x.meta = x.meta || {} | |
| x.meta.requestStartedAt = new Date().getTime(); | |
| return x; | |
| }) |
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
| // npm i axios | |
| const axios = require('axios').default; | |
| axios.interceptors.request.use( x => { | |
| // to avoid overwriting if another interceptor | |
| // already defined the same object (meta) | |
| x.meta = x.meta || {} | |
| x.meta.requestStartedAt = new Date().getTime(); | |
| return x; |
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
| const express = require('express'); | |
| const app = express(); | |
| app.use(express.json()); | |
| app.get('/', (req, res) => { | |
| res.send( { 'ok': true }); | |
| }); | |
| app.listen(3000); |
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
| // Manual approach, there is a better way | |
| const token = `${USERNAME}:${PASSWORD}`; | |
| const encodedToken = Buffer.from(token).toString('base64'); | |
| const headers = { 'Authorization': 'Basic '+ encodedToken }; | |
| const user = await axios.post(BASE_URL+'/users', data, { headers }) |
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
| const user = await axios.post(BASE_URL+'/users', data, { auth: { | |
| username: USERNAME, | |
| password: PASSWORD | |
| }}) |
OlderNewer