The restcups is a simple REST wrapper for CUPS printing server that allows you to print binary files to a specified CUPS printer over http.
The server listens for incoming requests and accepts binary data as input. It also accepts query parameters to specify printer options such as the number of copies and the "raw" option.
This endpoint returns a list of available printers on the CUPS server.
[
{
"name": "Brother_DCP_L2550DW_series"
},
{
"name": "Brother_DCP_L2550DW_series_b42200217f10_"
},
{
"name": "ZP450"
}
]
This endpoint accepts binary data as input and prints it to the specified printer with the specified options. The following query parameters are supported:
Parameter | Type | Description | Default Value |
---|---|---|---|
printer |
String | The printer name. | required |
copies |
Integer | The number of copies to print. | 1 |
raw |
Boolean | A boolean value indicating whether to print the file in "raw" format. | false |
The request body must contain binary data to print.
`POST /print?copies=2&raw=true HTTP/1.1 Host: localhost:8080 Content-Type: application/octet-stream [Binary Data]`
`HTTP/1.1 200 OK Content-Type: application/json {"message": "Print job submitted successfully"}`
- CUPS printing system installed and running
- firewall allow port 8080/custom port open
-
Clone or download the Print REST Server repository from GitHub.
-
Open a terminal and navigate to the root directory of the repository.
-
Run the following command to start the server:
go run server.go
This will start the server on port 8080. If you want to use a different port, you can specify it using the
--port
flag. For example:go run server.go --port 8888
-
Build or download restcups binary
go build
-
move to /user/bin
sudo mv ./restcups /usr/bin
-
Setup service on boot, default port 8080, change it to different port if needed by editing restcups.service
sudo cp ./restcups.service /etc/systemd/system && sudo chmod +x /etc/systemd/system/restcups.service
-
Start service
sudo systemctl start restcups
To print a file using the Print REST Server, you can use a tool such as curl
to send a POST
request with the file contents in the request body. For example:
curl -X POST -H "Content-Type: application/octet-stream" --data-binary "@label.pdf" "http://localhost:8080/print?printer=LP320&copies=2"
This will print the file "label.pdf" in current folder to the printer named "LP320" with 2 copies.
To get a list of available printers using the Print REST Server, you can use a tool such as curl
to send a GET
request to the /printers
endpoint. For example:
curl "http://localhost:8888/printers"
This will return a JSON object with a list of available printers.
The Print REST Server is released under the MIT License.