php - Clean solution for using APIs within Laravel? -


does have nice clean & code efficient solution using apis within laravel?

thanks

one thing lot of folks seem forget model in mvc. of time, abstraction layer database, don't have be. can service interacting external api.

so said, when building out feature on site uses external api, start creating model api. try name methods similar possible eloquent methods because used working , tends make sense.

these methods interact api , can use results api fill out collection object well. idea design model in way don't feel interacting third-party api.

on top of model, build repository contain business logic app requires interact api. example, if you'd need grab item api, might want check own database first cached version. if there none, grab item api , cache/recache , return results controller.

then you'd inject repository controller , whatever need it.

also, might pretty obvious, things api key , entry point api go in config files or .env file depending on laravel version using. best use service providers manage dependency injection in case ever need update model in event third party comes out newer api version want use. coding model interface in case has potential save headaches later.

and 1 last note, before start, check packagist first. there's no point in reinventing wheel.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -