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
ARG BUILD_IMAGE="node:18-slim" | |
ARG RUN_IMAGE="node:18-alpine" | |
############################## | |
######## build stage ######### | |
FROM $BUILD_IMAGE AS builder | |
WORKDIR /app | |
## Copy package.json files for caching dependencies |
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
#!/bin/bash | |
## Delete "branch1" on remote repository | |
git push origin --delete branch1 | |
## Delete "branch1" from local system | |
## "-D" is an alias for "--delete --force" | |
git branch -D branch1 |
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
#!/bin/bash | |
## Delete all branches without upstream | |
while read branch; do | |
upstream=$(git rev-parse --abbrev-ref $branch@{upstream} 2>/dev/null) | |
if [[ $? == 0 ]]; then | |
## Found upstream for branch | |
echo $branch tracks $upstream | |
else | |
## No Upstream! --> delete branch |
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
#!/bin/bash | |
## Create new local branch and push to remote | |
git co -b branch1 | |
git push --set-upstream origin branch1 | |
## Create new local branch and push to remote | |
git co -b branch2 | |
git push --set-upstream origin branch2 |
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
/** | |
* Returns a random integer between min (inclusive) and max (inclusive). | |
* @param {number} min The minimum value | |
* @param {number} max The maximum value | |
* @return {number} The random integer | |
*/ | |
const getRandomInt = (min, max) => { | |
min = Math.ceil(min); | |
max = Math.floor(max); | |
return Math.floor(Math.random() * (max - min + 1)) + min; |
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
// - Doing a GET request | |
let resp404 = client.get("https://httpbin.org/status/404") | |
.send() | |
.await?; | |
// - Matching the HTTP status code of the request | |
match resp404.status() { | |
// - "OK - 200" everything was good | |
reqwest::StatusCode::OK => { | |
println!("Success!"); |
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
// Create a Map of string key-value pairs | |
// to represent the body payload | |
let mut map = HashMap::new(); | |
map.insert("lang", "rust"); | |
map.insert("body", "json"); | |
// - Doing a POST request | |
// - Parse the response to the "JSONResponse" struct |
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
//... | |
// - Doing a GET request | |
// - Parse the response to the "GETAPIResponse" struct | |
let resp200 = client.get("https://httpbin.org/ip") | |
.header(CONTENT_TYPE, "application/json") | |
.send() | |
.await? | |
.json::<GETAPIResponse>() |
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
use std::collections::HashMap; | |
use serde::{Deserialize, Serialize}; | |
use reqwest::header::CONTENT_TYPE; | |
#[derive(Serialize, Deserialize, Debug)] | |
struct GETAPIResponse { | |
origin: String, | |
} |
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
[package] | |
name = "example_make_http_request" | |
version = "0.1.0" | |
edition = "2021" | |
[dependencies] | |
reqwest = { version = "0.11", features = ["json"] } | |
tokio = { version = "1", features = ["full"] } # for our async runtime | |
serde = { version = "1.0", features = ["derive"] } | |
serde_json = "1.0" |