The Department of Labor Developer Community

ColdFusion SDK

Table of contents

    SDK ZIP: 

    Add the SDK file to your project

    Extract the zipped SDK folder or grab the git repository.

    Copy the folder into your project.

     

    Using the SDK

    Create an SDK object in your source

    The SDK is used in an object-oriented manner.  In your page, create an object from the SDK’s CFC file:

    <cfscript> objSDK = CreateObject("component", "gov.dol.govAPISDK.SDK");</cfscript>

    Making API Calls

    The SDK has three properties it uses to make your calls:

    • API_KEY = API key
    • API_HOST = the host portion of the API'’s URL
    • API_URL = the URL of the API (minus the host and the method/file)

    The host, URL, and method/file are broken apart for easy reuse with consolidated and/or centralized APIs such as DOL’s.

    Before you can make your call, you need to set the values for the three properties:

    <cfset objSDK.API_KEY = "{insert your key here}"> <cfset objSDK.API_HOST = "http://api.dol.gov"> <cfset objSDK.API_URL = "/V1">

    The example above uses DOL's API. Some federal APIs' URLs are structured differently. For example, let's look at http://business.usa.gov/api/article/xml

    Let's look at the Census Bureau. For example, http://api.census.gov/data/2010/acs5?key={your key}&get=B02001_001E,NAME&for=state:06,36

    Next, create a local variable with the name of the method or file you wish to invoke:

    <cfset API_METHOD = "DOLAgency/Agencies">

    Once you have done that, define the arguments you want to send the API in a struct.  For example:

    <cfset API_ARGUMENTS = structnew()>
    <cfset API_ARGUMENTS.filter = "Agency eq 'OSHA'">

    Now, all that’s left is to call the API and get your results back.

    <cfscript>myAPICall = objSDK.submitRequest(API_METHOD,API_ARGUMENTS);</cfscript>

    As long as the data is returned as either JSON or XML, your data will be in the appropriate data type.  No deserialization should be needed.  Otherwise, you will receive the raw text back.

    Tags: 

    Back to Top