Have you ever tried to call a Web Service from .Net or Javascript ? It is pretty simple. Right? This is true if you are only doing GET requests without security. Things start to get complicated once your start using security and doing POST requests.
There are frameworks that make it easier, but even after you reduce the complexity by adding a library to handle Web Requests, parsing adds to the problem. Thinking about these two problem we designed an SDK for iKnode Applications that makes it extremely simple to execute from your client.
First, by handling ALL Web Requests without your client having to know about the security or how to do POST requests. Second it parses the results as as native C# classes or Javascript objects.
One very important aspect of the new SDK, is that you learn it once in any language, and you learn it for the rest. Right now we are only supporting C# and Javascript, but the Android and iOS SDKs are on the way and will be handled in the same way, focused completly on consitency.
It’s time to look at some code. Let’s say that we are building a User Service which is used to manage User information in the cloud:
usingSystem;usingiKnode.Applications;usingiKnodeSdk.UnitTest.Domain;namespaceiKnodeSdkTest{/// <summary>/// Defines the User Service./// </summary> [Application]publicclassUserService{/// <summary>/// Gets the User First Name by its identifier./// </summary>/// <param name="id">User Identifier.</param>/// <returns>User First Name/.</returns>publicstringGetFirstNameById(intid){return"Robert";}/// <summary>/// Gets the Most Common User First Name./// </summary>/// <returns>Most Common User First Name/.</returns>publicstringGetMostCommonFirstName(){return"John";}/// <summary>/// Gets the User by its identifier./// </summary>/// <param name="id">User Identifier.</param>/// <returns>User Information.</returns>publicUserGetById(intid){if(id!=1){returnnull;}returnnewUser(1,newFullName("John","Doe"));}/// <summary>/// Saves the User Information./// </summary>/// <param name="user">User Information.</param>/// <returns>User Identifier.</returns>publicintSave(Useruser){if(user==null){return-1;}//TODO: Here your store the User Information.returnuser.Id;}/// <summary>/// Creates a new User with the Default Information./// </summary>/// <returns>User Information.</returns> publicUserCreateDefault(){returnnewUser(2,newFullName("Jane","Doe"));}/// <summary>/// Creates a new User./// </summary>/// <param name="id">Identifier.</param>/// <param name="name">Name.</param>/// <returns>User Information.</returns> publicUserCreate(intid,FullNamename){returnnewUser(id,name);}}}
In this case we are going to have the following classes as part of the model to be shared by the service and the C# client. For the Javascript client the model is not required.
namespaceiKnodeSdkTest{/// <summary>/// Defines the Full Name class./// </summary> [Serializable]publicclassFullName{/// <summary>/// First Name./// </summary>publicstringFirstName;/// <summary>/// Last Name./// </summary>publicstringLastName;/// <summary>/// Initializes a new instance of the <see cref="FullName"/> class./// </summary>/// <param name="firstName">First Name/</param>/// <param name="lastName">Last Name.</param>publicFullName(stringfirstName,stringlastName){this.FirstName=firstName;this.LastName=lastName;}}/// <summary>/// Defines the User class./// </summary> [Serializable]publicclassUser{/// <summary>/// Identifier./// </summary>publicintId;/// <summary>/// Full Name./// </summary>publicFullNameName;/// <summary>/// Initializes a new instance of the <see cref="User"/> class./// </summary>/// <param name="id">Identifier.</param>/// <param name="name">Name.</param>publicUser(intid,FullNamename){this.Id=id;this.Name=name;}}}
Now in the C# client side, you would call the UserService in the following way:
C# Client
1234567891011
// Creating User Id 1 with Name jdoe.ApplicationClientuserSvc=newApplicationClient("https://api.iknode.com",UserId,ApiKey,"UserService");Useruser=userSvc.Execute<User>("Create",newMethodParameter("id",1),newMethodParameter("name","jdoe"));
Now in Javascript the same call would look like this: