Write your own client
Here you will learn how to create a client for Puth. Puth is on the one hand a http server over which you work via remote prcedure calls on the remote objects.
Puths Api#
We use the following 5 api endpoints to write our own client.
- Create Context:
POST /context
- Delete Context:
DELETE /context
- Call on Context:
PATCH /context/call
- Get on Context:
PATCH /context/get
- Set on Context:
PATCH /context/set
- Delete on Context:
PATCH /context/delete
#
Principles of remote object interactionsThe Api always returns one of the following types: GenericObject
, GenericValue
or Error
.
A GenericObject
response does not contain the actual object, it contains an Representation
(Object with id
, type
and represents
).
A GenericValue
response contains the actual value
. You only get a GenericValue response if the returning value, of f.e. a function call, is serializable.
Conclusion
The client never gets the actual objects on which you interact. It only knows the Representation
of objects, it is somewhat like a Handle/Pointer/Symbol.
#
Lets startOur goal is to connect to Puth, then create our first context, browser and page. Then we want to open a website. I will represent the actual http requests for this. You can use any language, i will just show some example prototype code in javascript for easier understanding.
#
Creating a new ContextTo create a new context we need to make a POST request to /context
.
#
Creating a new BrowserNow we have the Representation
of the Context. Next we want to instantiate a new Browser.
To create a new Browser we need to call the createBrowser
function on the context. So we need to make a PATCH request to /context/call
.
#
Creating a new PageNow we have the Representation
of the Browser. Next we want to instantiate a new Page.
To create a new Page we need to call the newPage
function on the Browser object within the context. Again we need to make a PATCH request to /context/call
but now containing the object with which we want to interact.
#
Opening a website on the pageNow we have the Representation
of the Page. Next we want to go to a website.
To go to a website on the page, we need to call the goto
function on the Page object within the context. Again we need to make a PATCH request to /context/call
but now containing the object with which we want to interact.
#
Working exampleThe following code illustrates what we have learned in this tutorial. Now you know how to interact with Puth. If you want to have a look on the official js client, you can go to LINK