Skip to content

Commit 82603b4

Browse files
committed
Initial Code & readme
1 parent 2b24ca8 commit 82603b4

File tree

13 files changed

+2083
-0
lines changed

13 files changed

+2083
-0
lines changed

.github/workflows/ci.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
workflow_dispatch:
8+
9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}
12+
13+
jobs:
14+
docker-image:
15+
runs-on: ubuntu-latest
16+
if: github.ref == 'refs/heads/master'
17+
18+
permissions:
19+
contents: read
20+
packages: write
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Set up QEMU
27+
uses: docker/setup-qemu-action@v3
28+
29+
- name: Set up Docker Buildx
30+
uses: docker/setup-buildx-action@v3
31+
32+
- name: Log in to the Container registry
33+
uses: docker/login-action@v3
34+
with:
35+
registry: ${{ env.REGISTRY }}
36+
username: ${{ github.actor }}
37+
password: ${{ secrets.GITHUB_TOKEN }}

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM python:3.13
2+
WORKDIR /code
3+
COPY ./requirements.txt /code/requirements.txt
4+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
5+
COPY ./restapi /code/restapi
6+
7+
CMD ["python", "-m", "restapi"]

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,73 @@
11
# ampq-restapi
22
A simple restapi for sending messages to an ampq based message broker
3+
4+
This app is a simple REST API that allows you to send messages to an AMQP-based message broker. based on aiopika and
5+
FastAPI.
6+
7+
This was designed to be used with RabbitMQ, but likely will work with any AMQP-based message broker.
8+
9+
## Usage
10+
### Dependencies
11+
- Python 3.11+
12+
- pip
13+
14+
### Environment Variables
15+
- `RPC_URI`: The URI of the message broker. E.G `amqp://guest:guest@localhost/`
16+
- `PORT`: The port to run the application on. (Default: 2000)
17+
18+
### Docker
19+
You cause pull the container from Github container registry
20+
```bash
21+
docker pull ghcr.io/iplsplatoon/ampq-restapi:master
22+
```
23+
24+
or use `ghcr.io/iplsplatoon/ampq-restapi:master` as the image name in your docker-compose file.
25+
26+
### Install: Bare Metal
27+
1. Install python dependencies with pip
28+
```bash
29+
pip install -r requirements.txt
30+
```
31+
32+
3. Run the application
33+
```bash
34+
python -m restapi
35+
```
36+
37+
### Making requests
38+
The application will run on port 2000 by default.
39+
40+
#### Docs
41+
The application is documented using OpenAPI.
42+
You can view the documentation by navigating to `http://localhost:2000/docs` in your web browser.
43+
44+
#### Send a message
45+
You can make a **POST** request to the `/rpc/response` endpoint with the following query parameters:
46+
47+
- `routing_key`: The routing key to use for the message. This is a required parameter.
48+
- `timeout`: The timeout for the request in seconds. (Default: Never)
49+
50+
You message body should be what ever you want to be sent, the app will convert this to a byte string and send it as the
51+
message body. We also use the `content_type` header to set the content type of the message that send to the message broken.
52+
53+
The response will be send back to what ever client you using back and will forward the body, headers and other
54+
properties from the response message.
55+
56+
_If you don't need a response, you can use the `/rpc/one_way` endpoint instead._
57+
58+
## Development
59+
60+
### Dependencies
61+
PDM is used for dependency management.
62+
63+
To install dependencies, run the following command:
64+
```bash
65+
pdm install
66+
```
67+
68+
### Linting
69+
We use `ruff` for linting and formatting. You can run the following command to lint and format the code:
70+
```bash
71+
ruff check
72+
ruff format
73+
```

0 commit comments

Comments
 (0)