Let's Build an API using Slim PHP Framework

Поделиться
HTML-код
  • Опубликовано: 1 май 2024
  • This video shows you how to build an API using the Slim PHP microframework. The API allows you to add, delete, modify, and fetch the details of cricket players via JSON HTTP requests. We'll also implement data validation, authentication, and error handling using middlewares.
    GitHub repo link: github.com/iabhinavr/slim-php...
    0:00 Intro
    1:53 Installing Composer
    5:53 Starting with the index.php file
    8:38 Setting up the server
    16:13 Installing Postman
    17:50 Adding Routes
    19:18 Connecting to the Database
    22:25 Routes continued...
    23:22 Using DBAL for Database Queries
    27:42 Understanding Dependency Injection
    31:03 Route to get all players
    32:22 Route to get a single player
    34:50 Route to add a new player
    35:33 Getting input data using Body Parser Middleware
    41:41 Route to update a player
    44:23 Route to delete a player
    45:43 Authentication
    54:40 Request data validation
    1:01:05 Handling Errors
    1:03:10 Storing credentials in dotenv file
    1:05:51 Final Notes
    Website: codingreflections.com
    ---------------------------------------
    Server providers:
    Linode: codingreflections.com/go/linode/
    DigitalOcean: codingreflections.com/go/digi...
    -------------------------------------------------------------
    Disclaimer:
    This video is based on my personal experiences and knowledge. There is no guarantee that the information shared is 100% accurate.
    Disclosure:
    This video and its description may contain affiliate links, which can earn us commission if someone purchases products using those links.
  • НаукаНаука

Комментарии • 12

  • @mahmoudibrahim9803
    @mahmoudibrahim9803 14 дней назад

    Thank you, great content

  • @kevinillu6037
    @kevinillu6037 4 месяца назад

    gracias por compartir, explicas bastante bien 👍

  • @Tengil
    @Tengil 8 месяцев назад +1

    I get error name to resolved. I am running it in WSL so maybe thats the issue

  • @leonardolopes9360
    @leonardolopes9360 Месяц назад +1

    👏🏻👏🏻👏🏻👏🏻👏🏻

  • @sandervanderwindt6743
    @sandervanderwindt6743 5 месяцев назад

    Thank you for the video. You did explain things very well. Now it is time to try to build a REST API myself. One question came to mind directly. Is it not possible to use the env file for the error handling settings?

  • @kingnothingfpv2303
    @kingnothingfpv2303 4 месяца назад

    in Error Handling section, showing an html output of an error is not a good use. that should be json formatted error response...

  • @smark87
    @smark87 5 месяцев назад

    Thanks for the video. There is only one thing I didn't understand: how is it possible to do $this->get('DB') in the api.php file to get the queryBuilder since you are not in a class and therefore there are no properties? Thank you

    • @CodingReflections
      @CodingReflections  5 месяцев назад +1

      $this keyword is used inside a callback function within the $app->get() call. It is something called closure or anonymous function in PHP, not a traditional class method. $app being an instance of the Slim app, $this inside the callback refers to that. That's what I've understood.

  • @tobianointing
    @tobianointing Год назад +2

    Great tutorial thank you for this.
    Please I am getting this error from the public/index.php:
    Fatal error: Uncaught TypeError: Argument 1 passed to Slim\Factory\AppFactory::setContainer() must be an instance of Psr\Container\ContainerInterface, instance of DI\Container given

    • @truthteachers
      @truthteachers 11 месяцев назад

      In fact the whole code from the start of PHP-DI was very vague and fails. I just followed it like a robot. I think the whole video from this point seems confusing. I may retry from the start and if it fails i will just dump it. To make it worse, Slim and PHP-DI dump cryptic messages which would beat the ancient Sumerian scripts.

    • @tobianointing
      @tobianointing 11 месяцев назад +1

      @@truthteachers so I actually resolved this issue by installing php-di/slim-bridge library.
      I think this is the new way to work with php di in the slim framework.

    • @CodingReflections
      @CodingReflections  11 месяцев назад

      You could try cloning the Github repo given in the description and see if that's working. I've updated the composer packages.