Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. In the Source Control tree of Workflow Studio, locate the API project and double-click it.



    You should see the project open as a solution in Visual Studio.

    Image RemovedImage Added

  2. Open the HelloAPI class and add a new method to the class that returns a string named GetHelloString().

    Code Block
    public dynamic GetHelloString(dynamic data)
    {
         string helloString = "Hello API!";
         return helloString;
    }

  3. Open the HelloAPIController class and add the following code to create the stub for a new anonymous method named GetHelloAPIString(). Decorate the method with ApiAllowAnonymous to allow anonymous access and use GET as the HTTP method.

    Code Block
    languagec#
    [ApiAllowAnonymous]
    [HttpGet]
    public IHttpActionResult GetHelloAPIString(HelloAPIInputModel model)
    {
        var results = _implInstance.GetHelloString(model);
        // Return object as JSON
        return Json((object)results);
    }

  4. Open the HelloAPIRoutes.cs file and uncomment the route code..

    Notice the GetRouteMaps() method defines a dictionary of routeMaps. Notice the default GetRouteMaps() method defines a dictionary of routeMaps. You can use this default method or replace the commented out code with your routes. We do this in this example.

    Code Block
    languagec#
    public IEnumerable<KeyValuePair<string, MapRouteModel>> GetRouteMaps()
    {
      var routeMaps = new Dictionary<string, MapRouteModel>();
      /*
        Your routes go here!
        Below is an example - 
    
        var map = new MapRouteModel();
        map.Name = 'mapApi';
        map.Route = 'services/v1/itshop/maps/{id}';
        map.Defaults = new { controller = 'Maps',action = 'GetMapsByMapsGUID', id = RouteParameter.Optional };
        routes['mapApi'] = map;
      */
        return routeMaps;
    }  
  5. Edit the default route so that it looks like the following code.

    Code Block
    languagec#
    public IEnumerable<KeyValuePair<string, MapRouteModel>> GetRouteMaps()
    {
        var routeMaps = new Dictionary<string, MapRouteModel>();
        var map = new MapRouteModel();
        map.Name = 'HelloAPI';
        map.Route = 'services/v1/HelloAPI/maps/{id}';
        map.Defaults = new { controller = 'HelloAPIController',action = 'GetHelloAPIString', id = RouteParameter.Optional };
        routes['mapApi'] = map;
    
        return routeMaps;
    } 

  6. Compile the class library.


  7. Click Close to close the Operations log. If you see any errors, check your code and then compile the class library again.


  8. Compile and publish the class library.


  9. Select No when prompted about restarting services.

  10. Reset IIS.

...