https://github.com/yqs112358/yaml2json-server
A simple server written in Go, support converting yaml to json through http requests
https://github.com/yqs112358/yaml2json-server
converter golang json yaml yaml2json
Last synced: 7 months ago
JSON representation
A simple server written in Go, support converting yaml to json through http requests
- Host: GitHub
- URL: https://github.com/yqs112358/yaml2json-server
- Owner: yqs112358
- License: apache-2.0
- Created: 2024-11-11T14:36:04.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-11-12T09:30:03.000Z (11 months ago)
- Last Synced: 2025-03-02T16:43:10.894Z (7 months ago)
- Topics: converter, golang, json, yaml, yaml2json
- Language: Go
- Homepage:
- Size: 12.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# yaml2json-server
A simple server, support converting yaml to json through http requests.## Deployment
### Binary
#### linux
```shell
./yaml2json-server --listen 0.0.0.0 --port 8080 --key 3kf7^21%P9d --sub-path "/convert"
```#### windows
```shell
yaml2json-server.exe --listen 0.0.0.0 --port 8080 --key 3kf7^21%P9d --sub-path "/convert"
```### In Docker
docker-compose.yml
```yaml
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:///convert` with Body:
```yaml
key1: 1234
key2:
nestedKey: "data"
```Response:
```json
{
"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
```shell
https:///convert?url=https%3A%2F%2Fanother-domain%2Fdir%2Fdata.yaml
```Response:
```json
{
"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
```shell
curl https:///convert?key=& ......
```#### HTTP Basic Auth
```shell
AUTH_DATA=$(echo -n ":" | base64)
curl -H "Authorization: Basic $AUTH_DATA" https:///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
```shell
go build -o ./dist -ldflags="-s -w" -trimpath yaml2json-server
```## Reference
y2jLib in [bronze1man/yaml2json](https://github.com/bronze1man/yaml2json)