Publishing my first public composer package
Two weeks ago I published my first composer package - a thin wrapper around Guzzle for fetching finance data from Alpha Vantage API. It actually got downloaded a couple of times.
What does it do
The usage boils down to:
- Setting your API key in .env
- Calling the package like this:
$res now holds an array of historical data from AV for BTC/USD prices aggregated by months.
Behind the scenes, it's a thin wrapper around Guzzle with named methods for the majority of Alpha Vantage's API endpoints.
It also transforms the response into an array. In retrospect that might not be the best solution, since it takes away user's ability to interact with Guzzle's response object. I might implement an optional default transformer of some kind in the future to tackle this.
My most recent side project was to create a simple graph of historical financial stock data for a few stocks I'm interested in where I can click on any date and it would google the stock name along with year and month - so I can quickly get an idea what events cause bumps and dips. I decided to use Laravel for backend and Alpha Vantage 's free API for getting the data.
Since the only PHP package, I found for Alpha Vantage - kokspflanze/alpha-vantage-api - had no documentation I decided to create a package out of the code I used in my project. And document it well.
Publishing a composer package
- Create an account on https://packagist.org
- Submit package's public repository and fill in basic package information
- Go to sleep with a sense of accomplishment and pride
Updating the package is just as easy.
The preferred way is to set up automatic updating, which is really easy if you're using Github or Bitbucket for your repository. It then automatically updates Packagist when your repository gets updated.
But you can also do it manually, by updating the code in your repository and clicking the big green Update button on Packagist.
- In my case, the first issue was filed right after the first download that wasn't me - just 4 days later. And thankfully 2 PRs as well. Why? The package I submitted just straight up didn't work - some namespace were capitalized (API) when they shouldn't have been (Api).
I never advertised the package anywhere (until now!) and it's a great feeling to get a few (~15 as of writing) downloads from people that decided to try it out purely on their own.
The first PRs and issue were a bit frightening. I've done enough pull requests and merges in my few years of web development. But this was the first time publicly with "my name" on the project. Cool and frightening at the same time. It didn't help that I felt really dumb for not finding those issues out myself though.
Also shoutouts to emmerink , whoever you are, for filing the issues and contributing to the project!
Next I'd like to contribute to someone else's open source project, but I still feel anxious about the quality of my code and tests.