Buenas pr谩cticas a nivel general
Convenciones para crear APIs: rutas y datos
驴Qu茅 son los HTTP Status Codes?
驴Qu茅 son los M茅todos HTTP?
Creaci贸n del proyecto
Boilerplate y estructura de datos en frameworks de backend
Creaci贸n de datos: factories y seeders
Consulta de datos: rutas y controladores
Consulta de datos con tablas relacionadas
Quiz: Creaci贸n del proyecto
Planificaci贸n y mantenimiento
驴C贸mo planificar el alcance de tus APIs?
Consistencia entre endpoints: recursos y colecciones
Recursos anidados o multinivel
Optimizaci贸n y auditor铆a de APIs
Alteraci贸n de datos
Validaci贸n de datos
Quiz: Planificaci贸n y mantenimiento
Funciones de seguridad
Autenticaci贸n vs. autorizaci贸n
Autorizaci贸n: tokens y middlewares
Autenticaci贸n: inicio de sesi贸n y generaci贸n de tokens
Corrigiendo bugs de seguridad
Pol铆ticas de acceso
Subir im谩genes desde API
驴Qu茅 es la autenticaci贸n?
Quiz: Funciones de seguridad
API Testing
API Testing
Testing en tags
Testing en recipes
Testing m茅todo store
Testing m茅todo update
Quiz: API Testing
API Breaking Changes
Versionamiento de la API
Evoluci贸n de la API: v2, paginaci贸n y TDD
Quiz: API Breaking Changes
Conclusiones
Recapitulaci贸n de las buenas pr谩cticas para desarrollo de APIs
Comparte tus buenas pr谩cticas con la comunidad
You don't have access to this class
Keep learning! Join and start boosting your career
To build an efficient and well-organized API in Laravel, it is essential to understand how to configure both controllers and routes. This process is essential to properly manage queries to our database. Below, we show you how to do it step by step.
We start by creating specific controllers for our API in Laravel, which helps to segment and organize the code in a professional way. Here's how to do it:
php artisan make:controller API/CategoryController
API
folder and inside it CategoryController
.recipes
and labels
following the same steps.php artisan make:controller API/RecipeControllerphp artisanmake:controller API/TagController
Once the controllers are ready, it's time to configure the routes so that our APIs can be accessed correctly.
Access the API routes file: Navigate to the API-specific routes file(routes/api.php
).
Configure routes using HTTP methods:
Route::get('categories', [CategoryController::class, 'index']);
Route::get('categories/{category}', [CategoryController::class, 'show']);
Import required controllers: Make sure to import correctly the controllers using use
.
It is important to check that our routes are configured correctly. You can do this directly from the terminal with an Artisan command.
php artisan route:list --path=api
The controllers are the core that allows you to perform database queries:
Index method to get all categories:
CategoryController
, define the index
method:public function index() { return Category::all();}
Show method for a specific category:
public function show(Category $category) { return $category;}
Do the same for recipes and tags:
Recipe
and Tag
.To ensure that the endpoints work correctly, it is advisable to use professional tools:
GET
requests to your API.Postman is essential for evaluating APIs because:
Performing these basic configurations and tests is crucial to ensure that your Laravel API is running efficiently and neatly, allowing interactions with the database to be fast and clear. Continue to explore and improve your Laravel skills to build robust and scalable web applications.
Contributions 9
Questions 0
la aplicacion mucho se lagea, deberian arreglar eso, hace que uno se pierda en los avances
Want to see more contributions, questions and answers from the community?