0

in my Laravel 5.7/mysql app I need to make external api to read some data from external app with get request and to write some data to my db with post request.

Which tools/scripts are there for this and how to make these requests safe?

MODIFIED : Thanks for feedbacks, but looks like I badly put my question The external app(I do not know what is it written with) need to read data from my app and write data to my Laravel 5 app.

And how have I to test these requests while on development locally ? Looks like I have to use Guzzle as in provided link? Which steps have I to take for safety on my side?

Thanks!

mstdmstd
  • 2,195
  • 17
  • 63
  • 140

1 Answers1

1

These three libraries are popular for your use-case:

If the database is local you can use Eloquent, If not, remote connection to that database may help. otherwise, if you only have API access you should consume eighter of above libraries or any alternative options to make an HTTP request your application might require.

Security-wise, as long as you are only making a request to a remote server, the Suggested way is to store any key or secret string related to authorizing your request (if applicable) in your .env to prevent it from committed to your version control systems. Needless to say to always handle any possible HTTP error your remote API might throw in order to prevent any unwanted error on your application side.

And as Abir Adak mentioned in the comment check this thread for further details.

Updated Answer: On the case of MODIFIED part, generally you have 3 popular options,

  • REST API

This blog post is a detailed walkthrough written for Laravel This one from Stack Overflow can help you with designing you API This last one can help you to develop a widely accepted API response and endpoints by following its specifications.

  • GraphQL Can save some time for developing your API, but I suggest to make sure that the consumers of your API are happy to use this option. GraphQ Laravel Package for GraphQL If using Laravel isn't a must, and you are using PostgreSQL, you might want to look at Hasura as well.

  • SOAP Have little knowledge on this option for Laravel, just know folks coding using C# and .net are happier to expose their API with this protocol. read more about it on WikiPedia

Postman is a great tool for testing your API or any other API.

Amirmasoud
  • 590
  • 4
  • 11
  • 27
  • Pls, look at MODIFIED – mstdmstd Apr 28 '20 at 07:53
  • Thanks! What do you think about https://laravel.com/docs/5.7/passport ? – mstdmstd Apr 28 '20 at 14:53
  • 1
    @mstdmstd if you want to authorize your requests, you can use Passport and then utilized personal token, for example. But I suggest taking a look at https://laravel.com/docs/7.x/sanctum or https://github.com/tymondesigns/jwt-auth They might be faster to configure for your described use-case. – Amirmasoud Apr 29 '20 at 04:02