This repository hosts the API Saco Cheio TV, a backend service designed to act as an intermediary for the official Saco Cheio TV API. Its primary purpose is to centralize and facilitate the manipulation of data from the official API, serving as a dedicated backend for the Saco Cheio TV mobile application. It offers a structured and secure interface to consume and potentially process content related to Saco Cheio TV, such as episodes, shows, and other media.
- π― Official API Proxy: Efficiently proxies and manipulates data from the external Saco Cheio TV API.
- π JWT Authentication: Secures API endpoints using JSON Web Tokens (JWT) for authenticated access.
- βοΈ RESTful Design: Provides a clean and intuitive RESTful interface for content consumption.
- π οΈ Environment-based Configuration: Easily configurable via
.env.phpfor different environments (development, production). - π Lightweight & Performant: Built with a minimal set of powerful PHP libraries for speed and efficiency.
- PHP: Version
7.4.29or higher. - Composer: PHP dependency manager.
-
Clone the repository
git clone https://github.com/Vitor-Carmo/api-sacocheio-tv.git cd api-sacocheio-tv -
Install dependencies
composer install
-
Environment setup
cp env.example.php .env.php
Open
.env.phpand configure your environment variables:APP_ENV: Application environment (e.g.,development,production).APP_DEBUG: Set totruefor development,falsefor production.JWT_SECRET: A strong, unique secret key for JWT signing.SACOCHEIO_API_KEY: Your API key for the official Saco Cheio TV API.SACOCHEIO_API_BASE_URL: The base URL of the official Saco Cheio TV API.
-
Web Server Configuration This API is designed to work with an Apache web server, utilizing the provided
.htaccessfile for URL rewriting.- Point your web server's document root to the
api-sacocheio-tvproject directory. - Ensure
mod_rewriteis enabled for Apache.
- Point your web server's document root to the
-
Start development server (Optional - for quick local testing without full web server setup) You can use PHP's built-in web server for simple local development, though it may not fully replicate
.htaccessrewrite rules for subdirectories. For full functionality, a proper Apache/Nginx setup is recommended.php -S localhost:8000
Note: With the built-in server, you might need to access
http://localhost:8000/index.php/your/api/endpointdirectly or adjust your host's routing.
api-sacocheio-tv/
βββ App/ # Core application logic
β βββ Controllers/ # Handles API request logic and prepares responses
β β βββ ApiController.php # Main controller for Saco Cheio TV API interactions
β βββ Middlewares/ # Middleware for request processing
β β βββ AuthMiddleware.php # Handles JWT authentication for protected routes
β βββ Services/ # Business logic and external API interactions
β β βββ SacocheioApiService.php # Manages communication with the official Saco Cheio TV API
β βββ Utils/ # Utility classes and helper functions
β βββ JwtUtil.php # Helper for JWT token creation and validation
βββ public/ # Publicly accessible files (can contain assets, though minimal for an API)
βββ tests/ # Placeholder for unit and integration tests
βββ .gitignore # Specifies intentionally untracked files to ignore
βββ .htaccess # Apache configuration for URL rewriting and routing
βββ .tool-versions # ASDF version manager configuration for PHP
βββ composer.json # Composer dependencies and autoloading configuration
βββ config.php # Global application configuration settings
βββ env.example.php # Example environment variables file
βββ index.php # Main entry point for all API requests, handles routing dispatch
Configure these variables in your .env.php file (copied from env.example.php):
| Variable | Description | Default | Required |
|---|---|---|---|
APP_ENV |
The application environment. | development |
Yes |
APP_DEBUG |
Enable/disable debug mode. | true |
Yes |
JWT_SECRET |
Secret key for signing and verifying JWTs. | - | Yes |
SACOCHEIO_API_KEY |
API key for accessing the official Saco Cheio TV API. | - | Yes |
SACOCHEIO_API_BASE_URL |
Base URL of the official Saco Cheio TV API. | - | Yes |
config.php: Contains general application configuration, such as API headers or other static settings..htaccess: Apache rewrite rules, essential for routing all requests throughindex.php.
The composer.json file does not define explicit development scripts. Standard Composer commands apply:
| Command | Description |
|---|---|
composer install |
Installs all project dependencies. |
composer update |
Updates all project dependencies to their latest allowed versions. |
composer dump-autoload |
Regenerates the autoloader. Useful after adding new classes. |
- Ensure prerequisites (PHP, Composer) are installed.
- Clone the repository and install dependencies.
- Configure
.env.php. - Set up your local web server (e.g., Apache) to point to the project directory and enable
mod_rewrite. - Access the API endpoints via your configured web server.
The tests/ directory is present, indicating a provision for automated tests. While specific testing commands are not in composer.json, it's generally expected that PHPUnit is used for PHP projects.
# Assuming PHPUnit is installed globally or via composer require-dev
./vendor/bin/phpunitFor production deployment, ensure APP_ENV is set to production and APP_DEBUG is false in your .env.php file. Configure your web server (Apache/Nginx) to serve the application and handle routing according to the .htaccess file.
- Traditional Hosting: Deploy to a PHP-enabled web server (e.g., Apache, Nginx) with
mod_rewriteenabled. - Cloud Hosting: Can be deployed on various cloud platforms that support PHP applications, such as AWS EC2, Google App Engine, or DigitalOcean Droplets.
The API endpoints are handled by FastRoute and dispatched through index.php to the App\Controllers\ApiController.php and its associated services.
Endpoints requiring authentication expect a JSON Web Token (JWT) to be passed in the Authorization header as a Bearer token:
Authorization: Bearer [YOUR_JWT_TOKEN]
Below are example endpoints inferred from the project's purpose of manipulating Saco Cheio TV content:
Authenticates a user and returns a JWT token.
Request Body:
{
"username": "your_username",
"password": "your_password"
}Response:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"expires_in": 3600
}Retrieves a list of shows from the Saco Cheio TV.
Authentication: Required
Response:
[
{
"id": "show-1",
"title": "Show Title 1",
"description": "Description of Show 1",
"image_url": "https://example.com/show1.jpg"
},
// ... more shows
]Retrieves a list of episodes for a specific show.
Authentication: Required
Parameters:
showId: The unique identifier of the show.
Response:
[
{
"id": "episode-1",
"title": "Episode Title 1",
"duration": "45:30",
"release_date": "2023-01-15",
"audio_url": "https://example.com/episode1.mp3"
},
// ... more episodes
]Retrieves details for a specific episode.
Authentication: Required
Parameters:
episodeId: The unique identifier of the episode.
Response:
{
"id": "episode-1",
"title": "Episode Title 1",
"description": "Full description of Episode 1",
"duration": "45:30",
"release_date": "2023-01-15",
"audio_url": "https://example.com/episode1.mp3",
"show_id": "show-1"
}We welcome contributions! Please see our Contributing Guide for details.
Ensure you have the prerequisites installed and follow the installation steps. When proposing changes, make sure to add/update tests where applicable.
This project is licensed under the MIT License - see the LICENSE file for details.
- PHP-DI for robust dependency injection.
- FastRoute for efficient routing.
- Laminas Diactoros for PSR-7 HTTP message implementation.
- firebase/php-jwt for seamless JWT handling.
- vlucas/phpdotenv for easy environment variable management.
- π§ Email: [contato.vitorcarmo@gmail.com]
- π Issues: GitHub Issues
β Star this repo if you find it helpful!
Made with β€οΈ by Vitor Carmo