I have a blog Application. I want to understand the best way to write API.
- Controllers: BlogController, ImageController, TagController, UserController.
- Model: Blog, User, Image, Tag
- Relationship: User has many blogs, Blog has many tags, Blog has one Image
API
post:user/{id}/blogs, BlogController@save
- Method 1: Use Blog, Image and Tag Model inside BlogController and save them from inside BlogController itself
- Method 2: Use Blog Model only inside BlogController and write function to save Image and Tag inside Blog Model and call those methods from BlogController.
-
Method 3: Use Blog Model only and call internal APIs to save Image and Tag Data (using dingo in laravel)
- post:user/{id}/blogs, BlogController@save
- post:blogs/{id}/images, ImageController@save
- post:blogs/{id}/tags, TagController@save
-
Method 4: Call three consecutive different API call from client to save Blog, tag and Image. (It will increase a lot of server load)
- post:user/{id}/blogs, BlogController@save
- post:blogs/{id}/images, ImageController@save
- post:blogs/{id}/tags, TagController@save
Basically I want to know the best way to create APIs. Advice
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire