https://github.com/simplymichael/simple-subscription-api
https://github.com/simplymichael/simple-subscription-api
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/simplymichael/simple-subscription-api
- Owner: simplymichael
- Created: 2024-04-13T13:50:26.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-13T18:49:20.000Z (about 1 year ago)
- Last Synced: 2024-12-30T00:50:39.228Z (5 months ago)
- Language: PHP
- Size: 91.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simple Subscription
A simple RESTful API subscription platform which allows users to subscribe to a website.
Whenever a new post is published on a particular website,
all its subscribers receive an email with the post title and description in it.## How to run
### Pre-requisites### 0. Stack
- PHP 8.*
- Laravel 11.*
- MySQL 8.3.*### 1. Configure MySQL database
- Ensure you have a MySQL database up and running.
- Create a MySQL database using the command `CREATE DATABASE `.
- Copy `.env.example` to `.env`.
- Update the database environment variable definitions as follows:
```bash
DB_CONNECTION=mysql
DB_HOST=
DB_PORT=
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
```### 2. Configure Email
- Update the email sending environment variable defintiions as follows:
```bash
MAIL_MAILER=
MAIL_HOST=
MAIL_PORT=
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=
MAIL_FROM_NAME="${APP_NAME}"
```### 3. Install dependencies
- Run `composer install` to install the necessary dependencies.### 4. Seed the database with websites
- Run `php artisan db:seed --class=WebsiteSeeder` to seed the database with website.## Available API Routes
----------------------------------------------------------------------------------------|
| ROUTE | METHOD | Description |
|---------------------------------|--------|--------------------------------------------|
|`/api/websites` | GET | Get the list of available websites. |
|`/api/websites/{id}/posts` | GET | Get the posts for a given website. |
|`/api/websites/{id}/posts/new` | POST | Create a new post for the given website. |
|`/websites/{id}/subscribers/new` | POST | Subscribe a new user to specified website. |## Creating a new post
To create a new post, you have to have to know the website that the post belongs to.
So, do the following:
- Send a GET request to: `/api/websites` to get the list of available websites.
- Copy the ID of the website for which you want to create a post.
- Send a POST request to `/api/websites/{id}/posts/new` with the following post body data:
- `title` [string] (required): The title of the post
- `description` [string] (required): A brief descriptiion of the post.
- `body` [string] (required): The body of the post.## Subscribing a new user to a post
To subscribe a new user to a website,
- Send a GET request to: `/api/websites` to get the list of available websites.
- Copy the ID of the website for which you want to subscribe a user.
- Send a POST request to `/api/websites/{id}/subscribers/new` with the following post body data:
- `subscriber_email` [string] (required): The email of the user to subscribe
- `subscriber_name` [string] (optional): The name of the user to subscribe.## Sending out (or queueing) notifications of published posts
- Run the custom command `php artisan app:process-notifications` to queue notifications of published posts.## Processing the queue
- Run `php artisan queue:work` to process the queued notifications.## SAMPLE POSTMAN COLLECTION
A sample postman collection has been included and is located at
simple-subscription.postman_collection.json