ver. 1956 (2333616)
services/apiref
services/apisrv
services/attrs
services/caches
services/caches/formatters
services/caches/map
services/caches/search
services/caches/shortcuts
services/logs
services/logs/images
services/oauth
services/replicate
services/users

Examples, libraries and tools

Tools

If you're just getting to know OKAPI, you might want to check out OKAPI Browser (screenshot), a basic OAuth Console for OKAPI methods. It is an open-source project. You can fork it on GitHub or simply install it here.

Are there any client libraries?

OKAPI does not require you to use any special libraries. You should use OKAPI "as is", via basic HTTP requests and responses.

However, if you know of any useful third-party libraries, then let us know. We may choose to post a link somewhere here.

PHP Example 1 - simple query

Please note that the examples below use extremely simplied error checking routines. If you want to be "professional", then you should catch all HTTP 400 Responses, read their bodies (OKAPI error messages), and deal with them more gracefully.

This will print the number of users in the Opencaching.PL installation:

PHP Example 2 - search for nearest geocaches

This will print the codes of some nearest unfound caches:

JavaScript Example

It is possible to access OKAPI directly from user's browser, without the need for server backend. OKAPI allows Cross-domain XHR requests. You can also use JSONP output format. There are some limitations of both these techniques though.

This example does the following:

  • Pulls the list of all OKAPI installations from one of the OKAPI servers and displays it in a select-box. Note, that this method does not require Consumer Key (Level 0 Authentication).
  • Asks you to share your location (modern browser can do that).
  • Retrieves a list of nearest geocaches. (This time, it needs to use a Consumer Key which you will have to supply.)

Run this example

C# Example

OKAPI Browser (already mentioned in the Tools section) is an open-source project. Written in C#.NET, uses the apisrv and apiref modules to dynamically retrieve the current list of OKAPI installations and methods. Get the source or try it first.

Comments