|
1 | 1 | # Example: Ad Server using Bun, ElysiaJS, and Dragonfly
|
2 | 2 |
|
| 3 | +In this example, we will build a real-time ad server API using Bun, ElysiaJS, and Dragonfly. |
| 4 | +In terms of data types, we use `Hash` to store ad metadata and `Set` to store ad categories and user preferences. |
| 5 | + |
3 | 6 | ## Packages Used
|
4 | 7 |
|
5 | 8 | - [ElysiaJS](https://elysiajs.com/) is a TypeScript framework supercharged by the [Bun](https://bun.sh/) runtime with end-to-end type safety.
|
@@ -28,3 +31,39 @@ bun run dev # (or `bun dev`)
|
28 | 31 | ```
|
29 | 32 |
|
30 | 33 | - The ad server API would be running on `http://localhost:3000/`
|
| 34 | + |
| 35 | +## Interact with the Ad Server API |
| 36 | + |
| 37 | +- Create ad metadata with the following request: |
| 38 | + |
| 39 | +```shell |
| 40 | +curl --request POST \ |
| 41 | + --url http://localhost:3888/ads \ |
| 42 | + --header 'Content-Type: application/json' \ |
| 43 | + --data '{ |
| 44 | + "id": "1", |
| 45 | + "title": "Dragonfly - a data store built for modern workloads", |
| 46 | + "category": "technology", |
| 47 | + "clickURL": "https://www.dragonflydb.io/", |
| 48 | + "imageURL": "https://www.dragonflydb.io/blog" |
| 49 | +}' |
| 50 | +``` |
| 51 | + |
| 52 | +- Create or update user preferences with the following request: |
| 53 | + |
| 54 | +```shell |
| 55 | +curl --request POST \ |
| 56 | + --url http://localhost:3888/ads/user_preferences \ |
| 57 | + --header 'Content-Type: application/json' \ |
| 58 | + --data '{ |
| 59 | + "userId": "1", |
| 60 | + "categories": ["technology", "sports"] |
| 61 | +}' |
| 62 | +``` |
| 63 | + |
| 64 | +- Retrieve ads for a specific user with the following request: |
| 65 | + |
| 66 | +```shell |
| 67 | +curl --request GET \ |
| 68 | + --url http://localhost:3888/ads/user_preferences/1 |
| 69 | +``` |
0 commit comments