Message:

Subscribe rss
Blog categories
All | Backendless features
How to Get Additional Information From Users’ Requests
July 9, 2019 by Oleg Vyalyh

How to get additional info about user requests Feature

Sometimes (or in some cases, every time) when you invoke a custom API Service, you may need additional information about the context from which the HTTP request was sent/received, such as user or device information. To collect that information, we provide a class called InvocationContext .

This class has a number of convenient methods to determine various request parameters. Until recently, there were six such parameters:

Only the last one is related to the http request itself –  getHttpHeaders .

Recently we added three more methods:

Let’s see what we can do with them now.

First, we need to download CodeRunner and create an API Service.

1) Download

Download CodeRunner and Create API Service

2) Create service

For our example, let’s collect statistics about geographical location of the visitors/users of our service. We’ll also add the ability to use an optional additional parameter to change the behavior of the service.

Test API Service

The code (please pay attention to the bold text):

The last step is to build the project and deploy the code, using ./bin/CodeRunner.sh .

Build the Project

Deploy API Service

That’s all there is to it. Thanks for reading, and happy coding!

Share this post
Tweet about this on TwitterShare on FacebookGoogle+