When should you use Saloon Package | LaraChamp
Back to Blog 3 min read

When should you use Saloon Package

I am working on the software for more than a year now. The software (multi-channel operations platform) connects with almost every sales channel (Amazon, Walmart etc.) Meanwhile, I got a chance to ref...

Gurpreet Kait

Gurpreet Kait

Author

Share:
Link copied to clipboard!

I am working on the software for more than a year now. The software (multi-channel operations platform) connects with almost every sales channel (Amazon, Walmart etc.) Meanwhile, I got a chance to refactor the api integrations using Saloon. I assume every one of you has worked on a large software code base. You may have dreamt of having a good, consistent structure. You can structure your Laravel apps into a modular approach or so-called patterns. But I’m pretty sure you’ve done abstraction at least once, maybe in your early days to handle the third-party api integrations.

Understanding Scenario

We were using a structure where you define headers and other required parameters for a request, which works perfectly fine with Guzzle. But it still becomes messy when you create a method just to ‘prepare’ a request. That’s fine if you only have a few requests, but once you add a lot—or add too much abstraction (like we had back then for APIs)—it turns into a problem. Our client class method always needed this extra line, and if you wanted to see what was really happening, you had to dig into the actual request method.


  
$response = $this->request(HttpMethodEnum::GET, "/orders/v0/orders/$orderId"); 

But In saloon how do you handle this?

Image shows how do you handle request in saloon package php

What Is Saloon

The Saloon package in PHP is a tool that makes it easier to connect your PHP application to other websites or services (like APIs) to get or send data. It's simple.

Why and How You Should Use Saloon You can easily find use cases of saloon from any AI agent. But the main idea is to understand how you want to structure your code.

WHY?

  • If you have a big codebase
  • If you want to structure your external apis better
  • Better documentation
  • Easy Debugging

Saloon has many features but I think these are the 4 points that I feel are good about saloon.

HOW?

The another question is to how to structure your apis? The first one is to have a Connector ( Connector is a main class where you define the authentication and any default header, body etc.) and the second thing is to create Request (Request is also a class the represents a single api request the request should be consumed through connector).


Image shows how the connector class looks like in saloon package php

This is what a better approach looks like.

How a connector works and how you can create a request are the things that you should learn from ChatGPT or from the Saloon website itself.

I just wanted to give you an idea what you can do to make your code base much better when using third party apis. if you have any question feel free to join the server and ask.

Discord

Enjoyed this article?

Subscribe to get more Laravel tutorials and development tips like this one

No spam, ever. Unsubscribe at any time.

Related Articles

Why Use Laravel Data?

I've been using Laravel Data for the last 1 month and I found that it's a time saver if you don't wa...

Packages Laravel

Saloon A PHP Package

Why This is Important?Well, I'm working at sku.io and in there we have many sales-channels integrati...

Packages
Articles Tags