Tyk is a popular API gateway and API management tool that can be used to quickly and securely manage APIs. Moesif is a great addition to the Tyk platform to augment everything from analytics to helping you set up metered billing.
Building your API is just the first step. Once built, you need to keep customers and services using the API happy. Moesif is the tool to help you do exactly that.
Integrating Moesif with your Tyk instance can be done in a few simple steps. In this blog I’ll show you how to:
- Create a Moesif Account
- Use the Moesif-Tyk plugin to integrate Moesif into Tyk
- Verify the integration
- Be ready to jump into docs and get started!
Step 1 - Creating Your Moesif Account
If you don’t already have a Moesif account, You’ll want to sign up. Once you’re registered you’ll need to add a few details.
- Organization Name
- The name of your organization or company
- App Name
- The name of the app you are integrating with Moesif
- What best matches your role?
- Here you can describe what your current role is at your organization. This helps us to assist you with relevant hints and tips in the future.
- What are you hoping to achieve?
- Here you can let us know how you’ll use Moesif to help your organization or project.
Once you’ve filled out these details, click Next. After this, you’ll be presented with a brief overview of Moesif.
Click Next once again.
Step 2 - Adding the Moesif Plugin to Tyk
After the Overview screen, you’ll be presented with the Quick Install screen. Here you can pick from any different server integrations and plugins. For Tyk, we want to make sure Tyk is selected in the left pane and that the Tyk walkthrough is displayed on the right.
You’ll also see the message which shows “No data received yet”. This shows that Moesif is now listening for events to come in through the plugin that we are about to install in our Tyk gateway.
In pump.env, generally found in the confs directory of a docker installation of Tyk, we will add the following lines:
MOESIF_APPLICATION_IDshould contain the Moesif Application ID associated with your application.
For example, here is what a complete example of the pump.env file may look like:
TYK_PMP_OMITCONFIGFILE=true TYK_PMP_ANALYTICSSTORAGETYPE=redis TYK_PMP_ANALYTICSSTORAGECONFIG_TYPE=redis TYK_PMP_ANALYTICSSTORAGECONFIG_ADDRS=tyk-redis:6379 TYK_PMP_ANALYTICSSTORAGECONFIG_USERNAME= TYK_PMP_ANALYTICSSTORAGECONFIG_PASSWORD= TYK_PMP_ANALYTICSSTORAGECONFIG_DATABASE=0 TYK_PMP_ANALYTICSSTORAGECONFIG_MAXIDLE=100 TYK_PMP_ANALYTICSSTORAGECONFIG_MAXACTIVE=100 TYK_PMP_ANALYTICSSTORAGECONFIG_ENABLECLUSTER=false TYK_PMP_PURGEDELAY=2 TYK_PMP_PUMPS_MOESIF_TYPE=moesif TYK_PMP_PUMPS_MOESIF_META_APPLICATIONID=MOESIF_APPLICATION_ID TYK_PMP_DONTPURGEUPTIMEDATA=false
Be sure to save this file.
Next, in the tyk.env file that is also in the confs directory, we will enable analytics on the gateway. To do this we will add the following lines under the
### analytics section in the config.
Once added, that section in the config should look similar to the example below.
### Analytics TYK_GW_ENABLEANALYTICS=true TYK_GW_ANALYTICSCONFIG_TYPE=mongo TYK_GW_ANALYTICSCONFIG_ENABLEDETAILEDRECORDING=true TYK_GW_ANALYTICSCONFIG_ENABLEGEOIP=false TYK_GW_ANALYTICSCONFIG_GEOIPDBLOCATION=./GeoLite2-City.mmdb TYK_GW_ANALYTICSCONFIG_NORMALISEURLS_ENABLED=true TYK_GW_ANALYTICSCONFIG_NORMALISEURLS_NORMALISEUUIDS=true TYK_GW_ANALYTICSCONFIG_NORMALISEURLS_NORMALISENUMBERS=true TYK_GW_ANALYTICSCONFIG_NORMALISEURLS_CUSTOM=
The last step is to restart Tyk (especially the Pump and Gateway components) to make sure the changes to the configs take effect.
Step 3 - Making Your First Request
Once your API gateway is back up and running, it’s time to send a request to your endpoint. You can use Postman, Insomnia, or an equivalent platform to send the GET request to your endpoints.
Regardless of how the request is sent, the Moesif integration into your application isn’t complete until the first request is sent and detected by Moesif. In the Moesif setup screen, before you send off the request, you should see a dialog at the bottom of the screen showing “No data received yet.” mentioned earlier.
Step 4 - Confirming Your Integration
After the request is sent, Moesif should receive the event and data. This may take a few moments for the first request to reflect in the system, once sent. Once received, Moesif will confirm that you are ready to move forward. The previous prompt will turn green and show “Data Received!”.
Lastly, in the green notification bar at bottom of the screen, click Next.
Step 5 - Inviting Your Team
The final step in the setup is to invite your team. The next screen is where you can do it quickly and easily.
If you’d like to add a team member, simply add their email and click Send Invite. If you don’t have any team members yet or want to skip this step, you can always add team members later.
Once you’ve added all the team members you want, click Finish.
You’ve now successfully integrated your API application with Moesif. You should now see the Moesif dashboard in the browser, ready to explore.