skip to Main Content

I am trying to find best practices for deeply integrating with an external API. I currently create services that can make calls to APIs, but when receiving data from these APIs I find myself having to validate and sanitize this data.

I am aware it is not possible to use Eloquent as an ORM for API data, but are there solutions our there or practices to ensure that data received from APIs are validated and sanitized?

I am working with the Shopify API and there are several endpoints that I am integrating with. If I had a framework or ORM that ensured all data received was formatted it would make it much easier to work with.

2

Answers


  1. You can validate data even outside or requests via the IlluminateSupportFacadesValidator facade like so:

    Validator::validate($data, $rules);
    
    Login or Signup to reply.
  2. To work with third-party APIs in Laravel, it is recommended to use Laravel Data. Laravel Data is a package that provides a simple and intuitive way to interact with various data sources, including APIs.

    With Laravel Data, you can easily define models that represent the data returned by an API. These models can then be used to interact with the API, making requests and handling responses in a familiar and consistent way.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search