Skip to content

Instantly share code, notes, and snippets.

View mr-pascal's full-sized avatar

Pascal mr-pascal

View GitHub Profile
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
#!/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
#!/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
#!/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
/**
* 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;
// - 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!");
// 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
//...
// - 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>()
use std::collections::HashMap;
use serde::{Deserialize, Serialize};
use reqwest::header::CONTENT_TYPE;
#[derive(Serialize, Deserialize, Debug)]
struct GETAPIResponse {
origin: String,
}
[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"