Laravel astrology API quickstart
A config entry, a service, a facade-friendly call.
Laravel's HTTP client and config system give you a clean home for the key and one place to change the base URL. This is the shape most Laravel projects converge on anyway - written out so you do not have to.
No official Laravel package. `Illuminate\Support\Facades\Http` covers it in a few lines.
Step 1
Config and env
Config files are cached in production, so read the env once here rather than calling `env()` at runtime.
// config/services.php
return [
// …
"astronode" => [
"key" => env("ASTRONODE_API_KEY"),
"base_url" => env("ASTRONODE_BASE_URL", "https://api.astronode.dev"),
],
];Step 2
A small service
One class, injectable anywhere. `throw()` turns a 4xx into a `RequestException` so your normal handler sees it.
<?php
namespace App\Services;
use Illuminate\Support\Facades\Http;
class AstroNode
{
public function post(string $path, array $body): array
{
return Http::withToken(config("services.astronode.key"))
->acceptJson()
->baseUrl(config("services.astronode.base_url"))
->timeout(15)
->retry(2, 200) // transient 5xx only
->post($path, $body)
->throw()
->json("data");
}
public function birthChart(array $birth): array
{
return $this->post("/v1/charts/birth", $birth);
}
}Step 3
Use it
Inject and call. The response is already unwrapped to the `data` payload.
<?php
namespace App\Http\Controllers;
use App\Services\AstroNode;
use Illuminate\Http\Request;
class ChartController extends Controller
{
public function store(Request $request, AstroNode $astro)
{
$birth = $request->validate([
"date" => ["required", "date_format:Y-m-d"],
"time" => ["required", "date_format:H:i:s"],
"tz_offset_minutes" => ["required", "integer", "between:-840,840"],
"lat" => ["required", "numeric", "between:-90,90"],
"lng" => ["required", "numeric", "between:-180,180"],
]);
return response()->json($astro->birthChart($birth));
}
}Next
Where to go from here
The call above is one of 110 endpoints. They all take the same bearer token and return the same envelope, so the second one is a path change. Each endpoint page carries its request fields and constraints.
Free tier covers 1,000 requests / month. No card, and test keys work on every endpoint.
Other languages