Calling an API with Authorization parameters

Laraship QuestionsCategory: TechnicalCalling an API with Authorization parameters
jedjie asked 5 years ago
Hello, I did checked the API Documentation already. :) What I want to know  is how to call the API with the Authorization Code? a mock example will be a great help, how can I pass the Authorization Parameters and Key values, just an example will do much. Snippets of a simple Get and a simple Post is enough. Thank you in advance.
1 Answers
Best Answer
laraship Staff answered 5 years ago
Hello, Please find the Insomnia Project to test calling APIs https://www.laraship.com/api/Laraship-Insomnia.json   You can download insomnia from here and import the JSON above to your workspace, then modify the domain URL to use your installation https://insomnia.rest/
jedjie replied 5 years ago

Thank you so much! this will be great. 🙂

jedjie replied 5 years ago

I already checked Insomia, its great! I can even generate code calling it on my Mobile Project. 😀 thank you so much. I will make an API routes to my Custom Modules, this will be great for testing. So good. Thank you!!! 😀

laraship Staff replied 5 years ago

🙂

jedjie replied 5 years ago

UPDATE: I am able to Authenticated Get and Post to my Module API now, thank you very much! Insomia a really great tool. 😀

public function getJournals(Request $request, Journal $journal)
{
try {
$journals = $this->journalService->getJournals();

$journals = (new JournalPresenter())->present($journals)['data'];

return apiResponse($journals);
} catch (\Exception $exception) {
return apiExceptionResponse($exception);
}
}

public function postJournals(Request $request, Journal $journal)
{
try {
$records = json_decode($request->getContent(), true);

DB::table('journals')->insert($records); // Eloquent approach

return apiResponse([], trans('Corals::messages.success.created', ['item' => 'Journal']));
} catch (\Exception $exception) {
return apiExceptionResponse($exception);
}
}