Home  >  Q&A  >  body text

Using ORM as API endpoint in Laravel

<p>I'm trying to find best practices for deep integration with external APIs. The service I'm currently creating can call APIs, but when receiving data from these APIs, I find myself having to validate and sanitize the data. </p> <p>I know it's not possible to use Eloquent as an ORM for API data, but do we have a solution or practice to ensure that the data received from the API is validated and sanitized? </p> <p>I'm using the Shopify API and I'm integrating multiple endpoints. It would be much easier to use if I had a framework or ORM that ensured all data received was formatted. </p>
P粉239089443P粉239089443382 days ago408

reply all(2)I'll reply

  • P粉178894235

    P粉1788942352023-09-06 16:00:08

    You can even validate the data externally or via the Illuminate\Support\Facades\Validator facade like this:

    Validator::validate($data, $rules);
    

    reply
    0
  • P粉253518620

    P粉2535186202023-09-06 09:28:06

    To use 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.

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

    reply
    0
  • Cancelreply