Showing posts with label API. Show all posts
Showing posts with label API. Show all posts

Monday, 8 May 2017

REST Web Service API Guidelines

When building web services, one of the primary benefits of using REST over SOAP is the intuitive nature of service interfaces.  However, this simplicity of interface can very easily be eroded.  Below are some suggested (and hence flame proof) guidelines that could be followed to ensure continued interface simplicity:

Resource-Oriented
  • REST is resource-oriented, not service-oriented.  Resources are nouns, not verbs.

Addressable
  • Every resource must be addressable by means of at least one URI (name).  Names must be meaningful.
  • Clients cannot access resources directly - they deal in representations of that resource (e.g, XML, JSON, ...)  
  • Resource representations would ideally be addressable (so that they can be passed around as URIs, eg. /rest/bookmarks.xml)  The use of HTTP accept headers to specify representation is however acceptable, but should be provided as well as the addressable URI.

Share:

Monday, 16 March 2015

Supporting Your Public Web API


No matter how beautiful and well-designed your new web API is, unless it is well supported, you may find that you become a victim of your own success.  Below are 4 suggested key elements of a supportable web API, based on my experiences at IG.


1. Documentation, documentation, documentation!

Unless it is easier to refer to your API documentation than to contact you, you will be contacted.  Don't assume anything is obvious.  Document your API in detail. Define your business terms.  Explain common interaction patterns.  Provide client code snippets and working samples in a variety of language bindings.   Provide a FAQ.

Consider providing a client SDK (Yes,I know REST is meant to be easy, but the reality is that unless your client is already a developer, they will struggle.  Make it easy for them to use your API.)

Consider providing a moderated forum to allow clients to answer each other's questions.  Provide an interactive API explorer allowing clients to try out APIs and see the raw HTTP requests and responses.


2. First and Second Line Support

Provide a "contact us" form instead of direct phone numbers.  The page should encourage clients to refer to API documentation, FAQ, and forum (if one exists).

Provide first line, "customer sensitive" support to answer common queries, or at least to ensure queries are well formulated before passing onto second line support.  If your organisation already has a customer services help desk, use them! They may balk initially at the perceived technical nature of the support, but should be helped past this by through training and provided access to simple debugging tools, e.g. the API explorer or a facility to search service log files.

Provide dedicated second line support via a rota consisting of the developers who built the API.

Maintain a searchable log of frequently answered questions (and answers).  Update the public FAQ from this log.


3. Effective error handling

Give API clients as much error information as possible in request responses.  If inputs are incorrect - tell them why.  If error codes are used - ensure these are documented.

Log every request in detail, including request authentication headers and body (subject to client privacy constraints).  Use a transaction id pattern to allow the flow of API requests to be tracked across multiple back-end systems.  Provide easy access to system logs, e.g. via Splunk, which provides a searchable index over a number of configured log files.  Splunk additionally allows requests to be charted and management dashboards to be created.  Senior management will want to know just how popular the API is.


4. Provide a barrier to entry

If, despite all of the above, the demand for your API is still overwhelming, consider:

  • throttling your API, with chargeable tiers for increased quotas
  • requiring that a verified account to be opened before an API can be used
  • providing support to valued customers only (or on a subscription basis).




Share:

Thursday, 10 July 2014

Excel REST Trading API Example

As much as I have a love-hate relationship with Microsoft, I have to admit the Excel has won me over as a power-user tool, particularly in the world of finance, where it may be used to access powerful back-end analytics servers to provide real-time yield curves and such like.

REST APIs such as IG's Web Trading API make this even easier, as this Excel VBA code snippet to get a list of open positions will hopefully demonstrate.  The sample assumes that a login /session request has already been executed and the client and account session tokens have been obtained.  The API key is the unique authorisation token required to access the API.

Public Function positions() As Collection

    ' Set up the HTTP access framework
    Set oXMLHTTP = CreateObject("MSXML2.XMLHTTP.6.0")
    ' Set the API URL
    Call oXMLHTTP.Open("GET", IG_API_HOST + "/positions", False)
    ' Set the HTTP request headers:
    ' Set the account session token
    Call oXMLHTTP.SetRequestHeader("X-SECURITY-TOKEN", m_accountToken)
    ' Set the client session token
    Call oXMLHTTP.SetRequestHeader("CST", m_clientToken)
    ' Set the API key
    Call oXMLHTTP.SetRequestHeader("X-IG-API-KEY", m_apiKey)
    ' Set the content type to JSON
    Call oXMLHTTP.SetRequestHeader("Content-Type", "application/json; chartset=utf-8")
    ' Set the requested response type to JSON
    Call oXMLHTTP.SetRequestHeader("Accept", "application/json; chartset=utf-8")
    ' Execute the request
    Call oXMLHTTP.send
    
    If oXMLHTTP.Status = 200 Then 
        ' Successful. A list of zero or more positions will have been returned
        ' Extract the response as a JSON object
        Dim data As Dictionary
        Set data = JSON.parse(oXMLHTTP.responseText)
        ' Get the list of positions from the response object
        Dim positions as Collection
        Set positions = data.Item("positions")
        ' If positions exist, iterate over the list         If Not positions Is Nothing Then
            Dim aPosition As Object
            ' Do something with the position, e.g. extract the instrument name of the underlying market
            For Each aPosition In positions
                  Dim instrumentName as String
                  Set instrumentName = aPosition.Item("market").Item("instrumentName")
                  ' etc
            Next
    Else 
        ' An error occurred
        MsgBox oXMLHTTP.responseText
        Set positions = Nothing
    End If
        
End Function
Share:

Monday, 30 June 2014

IG REST Trading API

Hot off the press is the news that IG (my esteemed employer) has launched its REST Trading API. 

The API provides REST-based and streaming access to a range of popular asset classes (including indices, forex, commodities, binaries and options), and includes functionality to:
  • Trade using risk management tools such as stops and limits
  • View real-time and historical market prices
  • Analyse market instrument and client sentiment information
  • Review account balances and trade history


IG already offers a well-established FIX API for corporate clients, but now with its new REST Trading API, IG's technology platform becomes much more easily and widely accessible, allowing for example:

  • Corporate partner integration without the start-up costs and complexity of FIX 
  • Trading strategy automation
  • Retail trading app development


The REST Trading API labs site offers getting started guides, API documentation, a downloadable sample trading app, and an interactive API companion app for trying out the REST APIs.  



The API will only be available in the UK initially, but the wider roll-out is imminent, so be sure to follow the labs site on Facebook or Twitter for updates.  

Related:

·         ForexMagnates: IG Opens API to Public Development, Launches IG Labs
·         FOW.com: IG rolls out new tech offering for traders


Share:

Tuesday, 19 February 2013

Wednesday, 24 October 2012

Web Service API Management

Service-oriented Architecture (SOA) web service API operations management requires a sophisticated service management organisation which is capable of defining and sustaining service levels to its customers across the enterprise. SOA without the service management will result in greater systems fragility and chaos.

ITIL is the widely adopted framework for implementing service management practices and so it figures that it would have relevance to SOA. Under ITIL services must become managed and supportable enterprise assets. This has the following requirements for an organisation:
Share:

Friday, 19 October 2012

Public Web Service API Management Solution

So, as part of your Service-oriented Architecture (SOA) strategy, you've decided to join the Web 2.0 rush to publicise your web service APIs and are wondering about how you might manage this.  Do you build something or are there 3rd party products to help?  The buy-vs-build decision is always a tough one, but you will need to consider your core business and competencies, as well as the product's support for the following:

Partner website - a public portal where consumers of your services will be able to register, obtain service keys, documentation, support, raise issues, join mailing lists, subscribe to RSS updates, download client libraries etc.

Key management - provision and management of API keys and ensure those are supplied with calls.  Support for OAUTH

Share:

Extensible Web Service API

The only constant in life is change, and this is no different for Service-oriented Architecture (SOA). Services must be built with this in mind: that they will have to adapt to new or changing requirements. Extensibility is the ability for services to adapt whilst preserving existing consumer contracts.

We would expect the following types of changes to services to have no impact on other consumers:
- internal source code changes
- interface changes
- take on of new consumers
- environmental changes
Share:

Thursday, 18 October 2012

What is Service-Oriented Architecture (SOA) - Competitive Services

I have been reviewing ITIL 3 with a view to updating my article on Service Management, and came across the notion of competitive services.

This is a very common notion when one looks at services in the usual, non-SOA sense where services are being offered in a market place and have to compete, but does it apply to SOA?

Well, clearly if you are looking at services offered in the internet by companies engaged in Cloud computing and such like, e.g. Google or Amazon, the answer is yes, but what about your typical corporate enterprise landscape?
Share:

Wednesday, 17 October 2012

Building a REST Java web service API using the Spring framework

Building a REST-ful Java web service API has never been more restful than now, using version 3+ of the Spring framework.

 First some annotated Java code:

@Component
@Controller()
public class SampleController {

     @Autowired
     private SampleService service;

     @RequestMapping(value = "/samples/{reference}", method = {RequestMethod.GET})
     @ResponseBody
     public Sample getSampleByReference(@PathVariable String reference) {
          return service.getSampleByReference(reference);
      }
 }

Share:

Friday, 12 October 2012

Key considerations for securing your REST web service API


Securing your REST service API layer is not just about considering whether you should use OAuth 2.0 or not, or whether REST needs something like WS-Security.  It is about considering why you should care about security, who you are protecting your service against, what the risks are, and more general security principles than just authentication and authorisation.

Why?

Do your service API need securing?  The answer to this will depend on your business, and the nature of the service, but you will want to consider whether there are any reputational, financial or regulatory consequences to a security breach of your service, and if so, how to deal with it appropriately.

Share:

Thursday, 11 October 2012

Java as a Service - Monitoring the Java Web Service API

One key aspect of managing your public REST web service API is understanding your client usage.

There are several options for doing this, including configuring your IP sprayer to do quota management, or facading your services with a 3rd party service management product like Layer 7 or SOA Software, but you might also consider the very simple Java web service based solution using the open source JAMon library.

The sample code below illustrates a simple per-IP address monitoring solution that you might customise to be per-account or whatever else is available in the HTTP request header.


Share:

Friday, 5 October 2012

REST Web Service API HTTP Response Status Codes

What HTTP status codes should your REST web service API be returning to clients?  Does it matter?  Before we launch into this topic, a quick recap of some interesting HTTP status codes:

200 - "OK"  All is well
204 - "No Content"  Nothing returned, but all is still well
400 - "Bad Request"  There is problem on the client's side
500 - "Internal Server Error" There is a problem on the server side
301 - "Moved Permanently" The resource has moved
303 - "See Other Server" Returns a URI to another resource
404 - "Not Found" Server has no clue what the client is asking for
409 - "Conflict" Client has tried to perform an operation that would leave one or more resources in an inconsistent state
401 - "Unauthorized" Client attempted access to a resource without providing the necessary authentication credentials
403 - "Forbidden" Client is not authorised to access a resource

Share:

REST Web Service API - Naming Guidelines

The following offers a suggested set of URI naming guidelines for REST web service APIs that have worked for me in practice.

The book RESTful Web Services RESTful Web Services defines three basic rules for url design which act as a great starting point:
  • Use path variables to encode hierarchy: /parent/child 
  • Put punctuation characters in path variables to avoid implying hierarchy where none exists: /parent/child1;child2 
  • Use query variables to imply inputs into an algorithm, for example: /search?q=jellyfish&start=20 
Share:

Thursday, 4 October 2012

What is Service Oriented Architecture - Loosely Coupled Services

What does it mean for a service to be loosely coupled in a Service-Oriented Architecture?

A service is said to be loosely coupled if its consumers are minimally impacted by changes to that service or its environment. Some coupling is obviously inevitable since the consumer has to make use of the service but can be minimised in a number of ways:

Share:

Wednesday, 3 October 2012

Going Public with your Web Service API - Taking Stock


If you are a good SOA believer, you will have a set of lovely services that are being used internally by your applications, and perhaps even by your commercial web applications, say via REST.  It will have dawned on you that your services are already public, being accessible over HTTP, and may have even discovered some enterprising customers have benefited from this fact by writing little client applications.  You think that perhaps it is time to go public, and produce an Amazon or Google style Public API for your business.

So what do you do?   First you need to take stock.

Why do you want to do this?  What is the business case?

Is your API suitable for making public i.e. is it well-designed, consistent, abstract, versioned, secure, monitored, documented, and adequate in capacity, availability and management terms?

Do you want to charge customers for this API?  What about 3rd parties who may want to leverage your API for their own customers?

Share: