Clone example source code from github repository:
git clone https://github.com/opwire/sample-cmdline-php.git
Change the project home to current working directory:
cd sample-cmdline-php
To download the latest opwire-agent
on Linux/macOS/BSD systems, run:
curl https://opwire.org/opwire-agent/install.sh | bash
For other systems:
- Download the relevant
opwire-agent
release, - Extract the
opwire-agent
oropwire-agent.exe
binary from the archive to example folder (current directory).
Execute the following command (with configuration file ./opwire-agent.cfg
):
./opwire-agent serve
Open the URL http://localhost:8888/$?type=microservice&type=php
:
Execute the following command:
./opwire-agent serve -p=8888 --default-command="php example.php"
Notice: above command is similar to
./opwire-agent serve -p=8888 --default-command="php example.php --format=json"
or
./opwire-agent serve -p=8888 --default-command="php example.php --input-format=json --output-format=json"
Make a HTTP request with curl
:
curl -v \
--request POST \
--url 'http://localhost:8888/$?type=microservice&type=php' \
--data '{
"name": "Opwire",
"url": "https://opwire.org/"
}'
Result:
> POST /$?type=microservice&type=php HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:8888
> Accept: */*
> Content-Length: 52
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 52 out of 52 bytes
< HTTP/1.1 200 OK
< Content-Type: text/plain
< X-Exec-Duration: 0.038846
< Date: Fri, 15 Mar 2019 11:16:53 GMT
< Content-Length: 686
<
{
"OPWIRE_EDITION": {
"revision": "b4cec6a",
"version": "v1.0.1"
},
"OPWIRE_REQUEST": {
"header": {
"Accept": [
"*\/*"
],
"Content-Length": [
"52"
],
"Content-Type": [
"application\/x-www-form-urlencoded"
],
"User-Agent": [
"curl\/7.35.0"
]
},
"query": {
"type": [
"microservice",
"php"
]
},
"params": null
},
"input": {
"name": "Opwire",
"url": "https:\/\/opwire.org\/"
}
}
Make a HTTP request with curl
:
curl -v \
--request POST \
--url 'http://localhost:8888/$?type=microservice&type=php' \
--data 'Not a JSON object'
Result:
> POST /$?type=microservice&type=php HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:8888
> Accept: */*
> Content-Length: 17
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 17 out of 17 bytes
< HTTP/1.1 500 Internal Server Error
< Content-Type: text/plain
< X-Error-Message: exit status 1
< Date: Fri, 15 Mar 2019 11:17:44 GMT
< Content-Length: 76
<
{
"name": "SyntaxError",
"message": "Syntax error, malformed JSON"
}
Execute the following command:
./opwire-agent serve -p=8888 \
--default-command="php example.php --input-format=json --output-format=text"
Make a HTTP request with curl
:
curl -v \
--request POST \
--url 'http://localhost:8888/$?type=microservice&type=php' \
--data '{
"name": "Opwire",
"url": "https://opwire.org/"
}'
Result:
> POST /$?type=microservice&type=php HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:8888
> Accept: */*
> Content-Length: 54
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 54 out of 54 bytes
< HTTP/1.1 200 OK
< Content-Type: text/plain
< X-Exec-Duration: 0.018843
< Date: Fri, 15 Mar 2019 11:19:36 GMT
< Content-Length: 554
<
OPWIRE_EDITION:
{
"revision": "b4cec6a",
"version": "v1.0.1"
}
OPWIRE_REQUEST:
{
"header": {
"Accept": [
"*\/*"
],
"Content-Length": [
"54"
],
"Content-Type": [
"application\/x-www-form-urlencoded"
],
"User-Agent": [
"curl\/7.35.0"
]
},
"query": {
"type": [
"microservice",
"php"
]
},
"params": null
}
input:
{
"name": "Opwire",
"url": "https:\/\/opwire.org\/"
}
Make a HTTP request with curl
:
curl -v \
--request POST \
--url 'http://localhost:8888/$?type=microservice&type=php' \
--data 'Not a JSON object'
Result:
> POST /$?type=microservice&type=php HTTP/1.1
> User-Agent: curl/7.35.0
> Host: localhost:8888
> Accept: */*
> Content-Length: 17
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 17 out of 17 bytes
< HTTP/1.1 500 Internal Server Error
< Content-Type: text/plain
< X-Error-Message: exit status 1
< Date: Fri, 15 Mar 2019 11:20:22 GMT
< Content-Length: 28
<
Syntax error, malformed JSON
- Fork it
- Create your feature branch (
git checkout -b your-new-feature
) - Commit your changes (
git commit -am "Add some feature"
) - Push to the branch (
git push origin your-new-feature
) - Create new Pull Request
MIT
See LICENSE to see the full text.