Une introduction à l'API Rails

API signifie Programme d'interface d'application, which provides one application to interact with ‘n’ number of applications which is of same/different language, to access the data/functionality.
Creating API application provides more scalability to the web applications. It will also helps for the easy integration with cross domain applications/languages.
• iOS apps
• Android apps
• Node js framework
• Angular js framework

There are 2 ways to achieve this in rails.

1. We can easily create a new API application using gem called API Rails, qui héritent de l'application de ActionControllerAPI au lieu de ActionControllerBase and it will skip view generation. This will also helps to configure the middlewares.

2. In case the application is already created we have to inherit ActionControllerAPI manually.

API de gestion des versions
Une fois l'application configurée, nous pouvons créer le contrôleur dans le dossier contrôleur/v1, ce qui facilitera la maintenance des versions et la publication de nouvelles versions des API. Dans ce contrôleur, nous pouvons écrire du code pour crud ou certaines fonctionnalités qui peuvent être appelées par curl ou en tant que requête API depuis une application frontale pour les requêtes GET, POST, DELETE, PATCH qui donnent des réponses au format JSON/xml, qui est sous une forme lisible par l'homme. . Ces données json peuvent être lues et affichées à partir d'une application frontale.

Sécurité
En passant le jeton qui est généré pour chaque utilisateur et e-mail of the user through an api header to secure an api. It can be ensured that there only authenticated user can access and modify data using api. Using these we can authenticate the user and secure the application. According to the data sent and the data matches in the applications we can send the proper responses back to the front-end application.

These are few basic aspects which can be implemented using rails and create a robust API architecture.

Prenez contact avec nous.

Sreedep Kumar

Développeur senior Ruby on Rails 

Abonnez-vous pour les dernières mises à jour

Articles Similaires

Laissez un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *

fr_FRFrench