SUGCON 2015 : Sitecore as a Content Repository Using Entity Service And SPEAK

21
Sitecore as a content repository using Entity Service, SPEAK Mike Robbins MVP Kagool @Sobek1985 Sitecore User Group Conference 2015 1

Transcript of SUGCON 2015 : Sitecore as a Content Repository Using Entity Service And SPEAK

Page 1: SUGCON 2015 : Sitecore as a Content Repository Using Entity Service And SPEAK

Sitecore User Group Conference 2015 1

Sitecore as a content repository using Entity Service,

SPEAK

Mike Robbins MVP

Kagool

@Sobek1985

Page 2: SUGCON 2015 : Sitecore as a Content Repository Using Entity Service And SPEAK

Sitecore User Group Conference 2015 2

What is Entity Service?

Page 3: SUGCON 2015 : Sitecore as a Content Repository Using Entity Service And SPEAK

Sitecore.Service.Client

Part of Sitecore.Services.Client providing ASP.NET Web API based web services.

Provides a framework for creating and extending web services using scaffolding.

Framework for both the server and client side.

Contains two web services

Item Service

Entity Service

Page 4: SUGCON 2015 : Sitecore as a Content Repository Using Entity Service And SPEAK

Entity Service Configuration

• Sitecore.Services.Client.config include file configures the services.

• Security access.

• Enable /disable anonymous access.

• Add Authorisation filters.

• Routing for services.

• Pipelines

• Any changes reflect across all services within SSC.

Page 5: SUGCON 2015 : Sitecore as a Content Repository Using Entity Service And SPEAK

Entity

• Define the business entity (model) to expose via the web service.

• Must implement the Sitecore.Services.Core.Model.EntityIdentity base

class.

• Decorate properties with .net validation attributes. (Required, RegEx. Etc)

• Support for adding custom client side validation to properties.

Page 6: SUGCON 2015 : Sitecore as a Content Repository Using Entity Service And SPEAK

Repository

• Implement the

Sitecore.Services.Core.IRepository<Entity> interface.

• Repository pattern scaffolding is added by the interface.

• Provide the business logic for each of the functions.

Page 7: SUGCON 2015 : Sitecore as a Content Repository Using Entity Service And SPEAK

Controller

• All functionality of the service is derived from the repository.

• Decorate the controller with [ServicesController]

• Implement the EntityService<Entity> base class.

• The service is flexible, easily extended with additional actions.

• Access to the controller can be restricted by using standard .net

MVC Authorisation Filters.

Page 8: SUGCON 2015 : Sitecore as a Content Repository Using Entity Service And SPEAK

SSC Demo App

Page 9: SUGCON 2015 : Sitecore as a Content Repository Using Entity Service And SPEAK

Demo – Model /Repository/Controller/IoC

Page 10: SUGCON 2015 : Sitecore as a Content Repository Using Entity Service And SPEAK

Consuming The Service

• There are three ways to consume a SSC service

1. Calling the Rest API directly

2. Consuming the service using the JavaScript API.

3. Using SPEAK components.

Controller routing

http://HostName/sitecore/api/ssc/namespace-to-controller/controller

Page 11: SUGCON 2015 : Sitecore as a Content Repository Using Entity Service And SPEAK

Sitecore User Group Conference 2015 11

JavaScript API

Page 12: SUGCON 2015 : Sitecore as a Content Repository Using Entity Service And SPEAK

JavaScript API

• Library to marshal calls between JavaScript and controller.

• Consume the service in a consistent way.

• Reference the JavaScript library for Entity Service.

"/sitecore/shell/client/Services/Assets/lib/entityservice.js"

var awesomeService = new entityService

({url: "/sitecore/api/ssc/MikeRobbins-Demo-controllers/Brochure“});

Page 13: SUGCON 2015 : Sitecore as a Content Repository Using Entity Service And SPEAK

Sitecore User Group Conference 2015 13

JavaScript API

• Auto mapping between POCO objects and JavaScript

• Provides validation, and loads in custom validators defined in

the entity.

• fetchEntities()

• fetchEntity(ItemId)

• destroy()

• save()• create(brochureJson)

Page 14: SUGCON 2015 : Sitecore as a Content Repository Using Entity Service And SPEAK

Demo – Create SPEAK PageCode

Page 15: SUGCON 2015 : Sitecore as a Content Repository Using Entity Service And SPEAK

Sitecore User Group Conference 2015 15

Extending Entity Service

Page 16: SUGCON 2015 : Sitecore as a Content Repository Using Entity Service And SPEAK

Extending Entity Service – Custom Actions

• The controller can be extended with additional actions.

• Standard Web API actions and attributes.

• The repository can be extended with additional functionality.

• Currently not available via the JavaScript API

• Default SSC routing

sitecore/api/ssc/Namespace-to-Controller/{controller}/{ID}/{action}

Page 17: SUGCON 2015 : Sitecore as a Content Repository Using Entity Service And SPEAK

Sitecore User Group Conference 2015 17

Extending Validation

• Based on standard .net DataAnnotations 

• Provide server-side validation for the type and a client-

side validation script.

• JavaScript validation script provided in meta data of

the service.

Page 18: SUGCON 2015 : Sitecore as a Content Repository Using Entity Service And SPEAK

Sitecore User Group Conference 2015 18

Validation / Testing

• Unit.js for validating data returns from the service and

unit testing.

Entity.should.be.an.instanceOf( EntityService.Entity );

Entity.isNew.should.be.false;

Entity.should.have.a.property(“Title");

Page 19: SUGCON 2015 : Sitecore as a Content Repository Using Entity Service And SPEAK

Sitecore User Group Conference 2015 19

Middleware

• Sits between the server side and promise callback.

• Inject client side logic into the promise before the

result is returned. Update or append to model

Page 20: SUGCON 2015 : Sitecore as a Content Repository Using Entity Service And SPEAK

Questions?

Entity Service Blog Posts

http://mikerobbins.co.uk/tag/ssc/

Entity Service Demo Application:

https://github.com/sobek1985/Seshat

https://github.com/sobek1985/EntityServiceDemo

Twitter:@Sobek1985

Page 21: SUGCON 2015 : Sitecore as a Content Repository Using Entity Service And SPEAK

Sitecore User Group Conference 2015 21

Thank you