Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

A Resource can have either one-to-many or many-to-many relationships with other Resources using property. The Class diagram below shows the relationship of resources in the Blog app

API to access Blog resource

Each resource has the following standard APIs:

...

Blog Category resource and other resources also have similar APIs

Resource response in JSON

A JSON presentation of a resource looks like an example below.
Blog Resource Response Example

Code Block
{
	"status": "success",
	"data": {
		"resource_name": "blog",
		"module_name": "blog",
		"title": "Et a dolor eum libero nostrum cumque.",
		"description": "Esse beatae voluptas officiis...",
		"module_id": "blog",
		"item_id": 0,
		"is_approved": true,
		"is_sponsor": false,
		"is_featured": false,
		"is_liked": false,
		"is_friend": false,
		"is_pending": false,
		"post_status": 1,
		"text": "Esse beatae voluptas officiis ratione ",
		"image": null,
		"statistic": {
			"total_like": 0,
			"total_comment": 0,
			"total_view": 1,
			"total_attachment": 0
		},
		"privacy": 0,
		"user": {
			"full_name": "Sheridan Hahn",
			"avatar": null,
			"id": 841
		},
		"categories": [
			{
				"id": 4,
				"name": "Family & Home",
				"subs": null
			},
			{
				"id": 9,
				"name": "Sports",
				"subs": null
			}
		],
		"tags": [
			{
				"tag_text": "tag me",
				"id": 3
			}
		],
		"attachments": [],
		"id": 1,
		"creation_date": "2016-06-21T04:53:48+00:00",
		"modification_date": null,
		"link": "http://localhost:7788/blog/1/et-a-dolor-eum-libero-nostrum-cumque/",
		"extra": {
			"can_view": true,
			"can_like": true,
			"can_share": true,
			"can_delete": true,
			"can_report": true,
			"can_add": true,
			"can_edit": true,
			"can_comment": true,
			"can_publish": false,
			"can_feature": true,
			"can_approve": false,
			"can_sponsor": true,
			"can_sponsor_in_feed": false,
			"can_purchase_sponsor": true
		},
		"self": null,
		"links": {
			"likes": {
				"ref": "mobile/like?item_type=blog&item_id=1"
			},
			"comments": {
				"ref": "mobile/comment?item_type=blog&item_id=1"
			}
		},
		"feed_param": {
			"item_id": 1,
			"comment_type_id": "blog",
			"total_comment": 0,
			"like_type_id": "blog",
			"total_like": 0,
			"feed_title": "Et a dolor eum libero nostrum cumque.",
			"feed_link": "http://localhost:7788/blog/1/et-a-dolor-eum-libero-nostrum-cumque/",
			"feed_is_liked": false,
			"feed_is_friend": false,
			"report_module": "blog"
		}
	},
	"error": null
}


Control Resource API

...

Response

In the new Core Mobile API app, we define ResourceBase class for controlling resource output, mapping data fields and generate routing generating routes for resource Resource API.
Every new resource Resource class should extend from the this base class and use the list of core resources for the its relationship when building APIs. It helps This way will help to reduce the code to build the API

Reusable core resources and common use cases

All resource class is classes are defined in the folder "PF.Site/Apps/core-mobile-api/Api/Resource" under name Space "\Apps\Core_MobileApi\Api\Resource"

Core's Resource

Description

Use Case

UserResource

Presentation of a Phpfox's User

  • Use for post's Author

TagResource

Tag feature in Phpfox

  • List of tags of a post (blog, event, listing)

NotificationResource

Core notification feature

  • Reuse notification feature for other resources

LikeResource

Core like feature

  • Reuse like feature for other resources

CommentResource

Core comment feature

  • Reuse comment feature for another resource

FriendResource

 

 

FileResource

 

 

FeedResource

 

 

AttachmentResource

 

 

...