In This Help TopicBuild a BlueStep JS APIHow to build a Relate API using BlueStep JS. In this API example, we will be working with a pretend Car Dealership group. They would like an API that returns all of their Dealerships and the Cars on their lots. Create a Record Type and Formnote: existing data can be used in place of creating components The fundamental part of an API is the the data you expect to send the caller, but first, we have to establish the data BlueStep needs to store.
Lets think about some of the data a Car Dealership group would want to store...
The list could go on and on, but for this example we will focus on Dealership Locations and the Cars on their lots. The first thing we need to do is create Relate Record Types. (See Relate Records - Introduction and Relate Records - Record Settings) We will create a Record Type for Dealerships and for Cars.
When creating a Record Type, we have to create it's Record Type Form as well. This is fundamental information that relates and identifies this record. Below our forms will contain some basic information about Dealerships and Cars.
Create a Record Querynote: existing queries can be used in place of creating components Now that we have configured Relate to store Dealerships and Cars, we need a way to query these records. This is where Relate Queries and Reports come into play (see Queries and Reports). Although Queries and Reports are sepereate components, they are smiliar in nature. We will use queries going forward in this example.
We need a query that will return all of our Dealership records so they can be used in our API End Point. In step 1 of our new Query wizard, we will say to include Dealership records.
In step 2 of the wizard, we will configure the Record Category and Unit constraints of the query.
Step 3 would contain any permanant search criteria (run time search critera can be added in our End Point)
Step 4 is our Display Columns
Step 5 are settings related to displaying the Query in the front end.
Although we will access Car records via their Dealership, we will create a similar Query for All Cars. This will allow us to properly import the Car records in our End Point. Create and configure a BlueStep JS End PointNow we are ready to create our BlueStep JS End Point which is where we will design and develop our API. After creating our component, we have a blank canvas to work with.
First, we want to configure the metadata for the End Point. The metadata is where we give our End Point a name, a Relate Strucuture location, the request path, IP Address restrictions, and set the HTTP Methods. See the image below for a basic configuration. After closing the metadata form, a JSON object is generated.
Next, we want to configure permissions for this End Point. We will do this using the Permissions Form.
Every Relate Component that is permissioned starts with some default permission groups (see Relate Forms - Permissions). There are a couple of ways to approach API Permissions. The easiest way is to use BlueStep native Authentication and Authorization. For this, you would set the "Everyone" permission group to "No Access" and configure the Permission Groups you want to have access to this API. If the call originates from a logged in user from the BlueStep site, no Authentication header needs to be provided. If the call originates from outside of BlueStep, Basic Authentication needs to be provided with a valid Username and Password in the site (See Basic Authentication). For the purposes of this example, we will set "Registerd Users" to "Reader" which will just required a logged in user. Like the metadata, permissions are represented by a JSON Object. Design APIDevelop API |