Skip to content

Commit 4f2a3c6

Browse files
authored
Merge pull request #22 from php-etl/feature/http-api
Pages for HTTP-APi & webhooks
2 parents 31b109a + 89901e6 commit 4f2a3c6

File tree

6 files changed

+423
-85
lines changed

6 files changed

+423
-85
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
- Edit theme design & layout in `themes/middleware`
1313
- Edit theme configuration in `config.toml`
1414

15-
Local : `hugo server -D`
15+
Open local server :
16+
- `hugo server -D`
17+
18+
Build static files:
19+
- `hugo`
1620

1721
## Maintainers
1822

config.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ hasChildren = true
6868
url = "core-concept/workflow"
6969
weight = 3
7070

71+
[[menu.main]]
72+
parent = "Core concepts"
73+
name = "HTTP Hook"
74+
url = "core-concept/http-hook"
75+
weight = 4
76+
77+
[[menu.main]]
78+
parent = "Core concepts"
79+
name = "HTTP API"
80+
url = "core-concept/http-api"
81+
weight = 5
82+
7183
[[menu.main]]
7284
weight = 3
7385
name = "Features"
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
---
2+
title: "HTTP API"
3+
date: 2020-07-12T15:21:02+02:00
4+
draft: true
5+
type: "component"
6+
logo: "pipeline"
7+
description: "Data stream processing at high rate and low memory consuming"
8+
weight: 5
9+
---
10+
11+
- [What is it ?](#what-is-it-)
12+
- [Installation](#installation)
13+
- [Basic usage](#basic-usage)
14+
- [Advanced usage](#advanced-usage)
15+
- [Adding JWT Authorization](#adding-json-web-token-jwt-authorization)
16+
- [Adding Basic HTTP Authorization](#adding-basic-http-authorization)
17+
18+
---
19+
20+
## What is it ?
21+
22+
This package allows you to create an API that will serve multiple endpoints.
23+
24+
The goal is to be able to send data to these endpoints, to process it in a series of steps.
25+
26+
## Installation
27+
28+
```
29+
composer require php-etl/workflow
30+
```
31+
32+
## Basic usage
33+
34+
To define your HTTP API, you need to specify a root `path`, and one or multiple `routes` under that root:
35+
36+
```yaml
37+
version: '0.3'
38+
satellites:
39+
my_satellite:
40+
label: 'Example of an api'
41+
filesystem:
42+
path: build
43+
composer:
44+
require:
45+
- "middlewares/uuid:dev-master"
46+
- "middlewares/base-path:dev-master"
47+
- "middlewares/request-handler:dev-master"
48+
- "middlewares/fast-route:dev-master"
49+
- "laminas/laminas-diactoros"
50+
- "laminas/laminas-httphandlerrunner"
51+
- "nyholm/psr7-server"
52+
- "nyholm/psr7"
53+
- "php-etl/pipeline"
54+
- "php-etl/satellite"
55+
- "php-etl/api-runtime"
56+
- "php-etl/mapping-contracts"
57+
http_api:
58+
name: 'My HTTP API' # Optional
59+
path: /my-api
60+
routes:
61+
- route: /transform
62+
name: 'A route to transform my products' # Optional
63+
method: 'post' # Optional. Default: "post"
64+
# Possible values: "get", "post", "put", "delete", "patch", "head"
65+
expression: 'input'
66+
pipeline:
67+
steps:
68+
- fastmap:
69+
map:
70+
- field: '[sku]'
71+
copy: '[product_name]'
72+
- field: '[id]'
73+
copy: '[product_code]'
74+
- csv:
75+
loader:
76+
file_path: 'output.csv'
77+
```
78+
79+
After [building](../../getting-started/compilation) the satellite, start a server in the path `build/`:
80+
81+
```bash
82+
bin/satellite run:api build/
83+
```
84+
85+
You can then send POST requests containing the data be processed to `http://localhost:8000/my-api/transform`
86+
87+
```yaml
88+
# input:
89+
[
90+
{ product_name: 'test_1', product_code: 861 },
91+
{ product_name: 'test_2', product_code: 862 }
92+
]
93+
94+
# response:
95+
{"message":{"accept":4,"reject":0,"error":0},"server":"my-computer.local"}
96+
97+
# output.csv:
98+
sku;id
99+
test_1;861
100+
test_2;862
101+
```
102+
103+
## Advanced usage
104+
105+
### Adding JSON Web Token (JWT) Authorization
106+
107+
```yaml
108+
# ...
109+
composer:
110+
require:
111+
- "tuupola/slim-jwt-auth"
112+
# ...
113+
http_api:
114+
authorization:
115+
jwt:
116+
secret: 'mysecret'
117+
```
118+
119+
With this config, each requests will need the header __Authorization__:
120+
|header|value|
121+
|-|-|
122+
|`Authorization`|`Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6Ik`[...]|
123+
124+
The string after "Bearer" is the token, generated from the secret phrase. This site can be used to generate a token from your own secret: [https://jwt.io](https://jwt.io)
125+
126+
### Adding Basic HTTP Authorization
127+
128+
```yaml
129+
# ...
130+
composer:
131+
require:
132+
- "tuupola/slim-basic-auth"
133+
# ...
134+
http_api:
135+
authorization:
136+
basic:
137+
- user: john
138+
password: mypassword
139+
- user: bill
140+
password: otherpassword
141+
```
142+
143+
The `basic` node is an array, and can contain multiple user/password pairs.
144+
145+
With this configuration, each requests will need the header __Authorization__:
146+
|header|value|
147+
|-|-|
148+
|`Authorization`|`Basic am9objpteXBhc3N3b3Jk`|
149+
150+
The string after "Basic" is the combination `user:password` encoded in Base64.
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
---
2+
title: "HTTP Hook"
3+
date: 2020-07-12T15:21:02+02:00
4+
draft: true
5+
type: "component"
6+
logo: "pipeline"
7+
description: "Data stream processing at high rate and low memory consuming"
8+
weight: 4
9+
---
10+
11+
- [What is it ?](#what-is-it-)
12+
- [Installation](#installation)
13+
- [Basic usage](#basic-usage)
14+
- [Advanced usage](#advanced-usage)
15+
- [Adding JWT Authorization](#adding-json-web-token-jwt-authorization)
16+
- [Adding Basic HTTP Authorization](#adding-basic-http-authorization)
17+
18+
---
19+
20+
## What is it ?
21+
22+
This package allows you to create an API that will serve a single endpoint.
23+
24+
The goal is to be able to send data to this endpoint, to process it in a series of steps.
25+
26+
## Installation
27+
28+
```
29+
composer require php-etl/workflow
30+
```
31+
32+
## Basic usage
33+
34+
Your HTTP Hook will serve the route set in the option `path`:
35+
36+
```yaml
37+
version: '0.3'
38+
satellites:
39+
my_satellite:
40+
label: 'Example of a hook'
41+
filesystem:
42+
path: build
43+
composer:
44+
require:
45+
- "middlewares/uuid:dev-master"
46+
- "middlewares/base-path:dev-master"
47+
- "middlewares/request-handler:dev-master"
48+
- "middlewares/fast-route:dev-master"
49+
- "laminas/laminas-diactoros"
50+
- "laminas/laminas-httphandlerrunner"
51+
- "nyholm/psr7-server"
52+
- "nyholm/psr7"
53+
- "php-etl/pipeline"
54+
- "php-etl/satellite"
55+
- "php-etl/api-runtime"
56+
- "php-etl/mapping-contracts"
57+
http_hook:
58+
name: 'My HTTP Hook' # Optional
59+
path: /my-hook
60+
expression: 'input'
61+
pipeline:
62+
steps:
63+
- fastmap:
64+
map:
65+
- field: '[sku]'
66+
copy: '[product_name]'
67+
- field: '[id]'
68+
copy: '[product_code]'
69+
- csv:
70+
loader:
71+
file_path: 'output.csv'
72+
```
73+
74+
After [building](../../getting-started/compilation) the satellite, start a server in the path `build/`:
75+
76+
```bash
77+
bin/satellite run:hook build/
78+
```
79+
80+
You can then send POST requests containing the data be processed to `http://localhost:8000/my-hook`
81+
82+
```yaml
83+
# input:
84+
[
85+
{ product_name: 'test_1', product_code: 861 },
86+
{ product_name: 'test_2', product_code: 862 }
87+
]
88+
89+
# response:
90+
{"message":{"accept":4,"reject":0,"error":0},"server":"my-computer.local"}
91+
92+
# output.csv:
93+
sku;id
94+
test_1;861
95+
test_2;862
96+
```
97+
98+
## Advanced usage
99+
100+
### Adding JSON Web Token (JWT) Authorization
101+
102+
```yaml
103+
# ...
104+
composer:
105+
require:
106+
- "tuupola/slim-jwt-auth"
107+
# ...
108+
http_hook:
109+
authorization:
110+
jwt:
111+
secret: 'mysecret'
112+
```
113+
114+
With this config, each requests will need the header __Authorization__:
115+
|header|value|
116+
|-|-|
117+
|`Authorization`|`Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6Ik`[...]|
118+
119+
The string after "Bearer" is the token, generated from the secret phrase. This site can be used to generate a token from your own secret: [https://jwt.io](https://jwt.io)
120+
121+
### Adding Basic HTTP Authorization
122+
123+
```yaml
124+
# ...
125+
composer:
126+
require:
127+
- "tuupola/slim-basic-auth"
128+
# ...
129+
http_hook:
130+
authorization:
131+
basic:
132+
- user: john
133+
password: mypassword
134+
- user: bill
135+
password: otherpassword
136+
```
137+
138+
The `basic` node is an array, and can contain multiple user/password pairs.
139+
140+
With this configuration, each requests will need the header __Authorization__:
141+
|header|value|
142+
|-|-|
143+
|`Authorization`|`Basic am9objpteXBhc3N3b3Jk`|
144+
145+
The string after "Basic" is the combination `user:password` encoded in Base64.

0 commit comments

Comments
 (0)