Skip to content

A simple server, support converting yaml to json through http requests

License

Notifications You must be signed in to change notification settings

yqs112358/yaml2json-server

Repository files navigation

yaml2json-server

A simple server, support converting yaml to json through http requests.

Deployment

Binary

linux

./yaml2json-server --listen 0.0.0.0 --port 8080 --key 3kf7^21%P9d --sub-path "/convert"

windows

yaml2json-server.exe --listen 0.0.0.0 --port 8080 --key 3kf7^21%P9d --sub-path "/convert"

In Docker

docker-compose.yml

services:
  yaml2json-server:
    container_name: "yaml2json-server"
    image: "yqs112358/yaml2json-server"
    restart: unless-stopped
    environment:
      Y2JS_LISTEN_ADDR: "0.0.0.0"
      Y2JS_LISTEN_PORT: 8080
      Y2JS_AUTH_KEY: "3kf7^21%P9d"
      Y2JS_URL_SUB_PATH: "/convert"
    ports:
      - 8080:8080

Usage

YAML in POST Request

Convert the YAML plain text in POST request body to JSON.

Example

Make a POST request to https://<YOUR-SERVER-ADDRESS>/convert with Body:

key1: 1234
key2:
  nestedKey: "data"

Response:

{
    "key1": 1234,
    "key2": {
        "nestedKey": "data"
    }
}

YAML from given URL

Read YAML text from the given URL-encoded URL, then convert to JSON.

Example

Make a GET request to

https://<YOUR-SERVER-ADDRESS>/convert?url=https%3A%2F%2Fanother-domain%2Fdir%2Fdata.yaml

Response:

{
    "key1": 1234,
    "key2": {
        "nestedKey": "data"
    }
}

Authentication

Pre-shared auth key set in the configuration to avoid http-api abuse. Use one of the following methods to carry the key with request:

URL paramater

curl https://<YOUR-SERVER-ADDRESS>/convert?key=<YOUR-AUTH-KEY>& ......

HTTP Basic Auth

AUTH_DATA=$(echo -n ":<YOUR-AUTH-KEY>" | base64)
curl -H "Authorization: Basic $AUTH_DATA" https://<YOUR-SERVER-ADDRESS>/convert ...

Configurations

Command-line Arg Environment Var Default Value Description
--listen Y2JS_LISTEN_ADDR "0.0.0.0" HTTP listen address
--port Y2JS_LISTEN_PORT 8080 HTTP listen port
--key Y2JS_AUTH_KEY "" HTTP-API auth key
--sub-path Y2JS_URL_SUB_PATH "/" HTTP Serve sub-path

Build

go build -o ./dist -ldflags="-s -w" -trimpath yaml2json-server

Reference

y2jLib in bronze1man/yaml2json

About

A simple server, support converting yaml to json through http requests

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages