Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/chris-rock/vesper

🍸Vesper - HTTP Framework for Bash Shell
https://github.com/chris-rock/vesper

bash bourne-shell framework http shell

Last synced: about 2 months ago
JSON representation

🍸Vesper - HTTP Framework for Bash Shell

Lists

README

        

# Vesper - HTTP Framework for Bash Shell

![Vesper Logo](assets/logo.png)

`vesper` is a collection of shell functions to make it super easy to generate valid http responses. Vesper is not a web server itself, its just the framework to parse http requests and generate valid responses.

## This is crazy, who needs a http framework for unix shell?

That is a very good question! If you would have asked me that question a year ago, I would have argued: nobody. Now, I am not sure anymore. How will sh/bash scripts work in the future of cloud and serverless? Consider reading my blog [Introducing Vesper - HTTP Framework for Unix Shell](https://lollyrock.com/posts/vesper-intro-bash-shell-http-framework/).

## Get Started

**Hello World**

```bash
source "vesper.sh"

# parses the http request
http_request

# generate the response
http_response StatusOK "text/plain"
echo 'Hello World'
echo $HTTP_REQUEST_URI
```

**Generate an Image**

```bassh
source "vesper.sh"

http_response StatusOK "image/jpeg"
echo "James Bond" | convert -font Arial -pointsize 72 -fill white -background black text:- -trim png:- >&1
```

**Seeing is believing**

```bash
# hello world example
ncat -lk -p 8081 --sh-exec examples/helloworld.sh

# json example
ncat -lk -p 8081 --sh-exec examples/json.sh

# image example
ncat -lk -p 8081 --sh-exec examples/image.sh

# pdf example
ncat -lk -p 8081 --sh-exec examples/pdf.sh

# file streaming example
ncat -lk -p 8081 --sh-exec examples/file_stream.sh

# router example
ncat -lk -p 8081 --sh-exec examples/router.sh
```

## Examples

* [Text](./examples/helloworld.sh)
* [JSON](./examples/json.sh)
* [Image](./examples/image.sh)
* [PDF](./examples/pdf.sh)
* [File Stream](./examples/file_stream.sh)
* [Router](./examples/router.sh)

To see all the examples in place justs run:

Start the server

```bash
# download the test pdf
wget http://tiswww.case.edu/php/chet/bash/rose94.pdf

# start the server
ncat -lk -p 8081 --sh-exec ./examples/router.sh
```

![vesper cli](assets/vesper_cli.png)

Visit the url localhost:8081

![vesper browser output](assets/vesper_browser.png)

## Dependencies

- `ncat` - used to execute the bash scripts on incoming requests
- `cat` - used to pipe file content
- `file` - used to determine the mime type
- `stat` - used to determine the file size

**Debian**

```bash
apt-get install ncat
apt-get install file
```

**Centos**

```bash
yum install nmap
yum install file
```

**Mac**

```bash
brew install nmap
```

## FAQ

**Why is the project named vesper?**

Popular web frameworks like [martini](https://github.com/go-martini/martini) and [gin](https://github.com/gin-gonic/gin) are named after cocktails and one of James Bond's famous cocktails is called vesper.

**Is vesper production ready?**

Its build on tooling that is around for decades. The foundation is battle-tested. While this is the case, its not designed for web-scale workloads.

**Should I switch from my popular http framework X to vesper?**

Most likely not

**Are there limitations**

At this point, its only tested with http GET methods

## Open questions

* What is the best way to handle execution errors?
* What is the stable way to verify http query params?

## Authors

* **Christoph Hartmann** - *Research & Prototype* - [chris-rock](https://github.com/chris-rock)

See also the list of [contributors](https://github.com/chris-rock/vesper/contributors) who participated in this project.

## Sponsors

The research and the development was sponsored by [mondoo](https://mondoo.io/)

## License

This project is licensed under the Apache 2 License - see the [LICENSE.md](LICENSE.md) file for details

## Acknowledgments

[shinatra](https://github.com/benrady/shinatra) and [bashttpd](https://github.com/avleen/bashttpd) also prototyped around http in bash.