/
3.4 - Server-side Interactions (Web APIs)

3.4 - Server-side Interactions (Web APIs)


Overview:

Server-side interactions can be hosted within your answerSpace. These are most commonly used as web APIs, or proxies between your client side code and an external service where you need to keep authentication details private.

It is also possible to use Server Side interactions directly, linking to them as a normal page from within your answerSpace, however it isn’t recommended as a general rule, as this can bring up issues if a user is accessing the app without being connected to the internet.


Creating Your Server Side Interaction:

To create a server side interaction, in the Interaction Manager, go to the “Manage” menu, and select “Interactions”.

This will list all of the interactions in your answerSpace.

To create a new interaction, select “Add”.

Name your interaction - keep in mind this is the name in the URL bar, so stick to standard alpha-numeric characters, and don’t use spaces.

For “Type”, select “MADL”. A MADL interaction is a server side interaction, that also has access to MADL code, a helper library we offer that allows you to do common things such as fetch remote URLs (similar to CURL), or send emails, or even generate PDFs.


Editing Your Interaction:

Once you’ve created an interaction, you will be viewing the Interaction page. Scroll down to the “Interaction Behavior” section. This is where where your code goes.

Click on the “Edit” button in the “MADL Code” box. This will open a code editor where you can write your server side PHP code.


Keep in mind you don’t need to add <?php ?> tags to your code.
Tip: The answerSpace server side code offers PHP scripting language. For Node.JS, consider using the Server CLI



Save and View:

To Save your interaction, click the “Save” button. You can now view your changes as a web app.


Server Side Code as a Web API:

If you’re using your server side interaction as a web API (the method most commonly used for app development), then you can access your new web API endpoint though the URL similar to:


https://blinkm.co/_api/interaction/run/ANSWERSPACE/INTERACTION


So if your answerSpace name is “myanswerspace”, and your MADL interaction is “myapi”, then your full URL would be:


https://blinkm.co/_api/interaction/run/myanswerspace/myapi/


Server Side Code as an Interaction Within Your App:

If you want to link your user directly to your server side interaction, within the BlinkMobile answerSpace framework, then you can view your interaction as a web app.


Tip: We recommend using Chrome, however most functionality and dev tools are reasonably compatible and complete over the major, recent release browsers.


To view your answerSpace, go to:


https://blinkm.co/myAnswerSpaceName


...where myAnswerSpaceName is the name of your answerSpace. If you haven’t yet set a Home interaction, then you should see a list of all of your new interactions, including the one you just created. Click on it to view the page.

Use the browser console to help debug any script errors you may have.


Tip: If you get a blank screen with no errors displayed, check the Network tab in your browser Dev Tools, and view the output for that particular network call. This can display more debugging information.


Next: