Code Monkey home page Code Monkey logo

publicrest's Introduction

Public RESTful API

What is PublicRest?

PublicRest is a set of publicly accessible RESTful APIs.

Limitation

The request rate is limited to 50 requests per second.

APIs

The root url is publicrest.co. It supports both HTTP and HTTPS, HTTPS is preferred.

Location

GET /util/loc/ip

Get the ip of the client.

Example: https://publicrest.co/util/loc/ip

Output:

{"ip":"xxx.xxx.xxx.xxx"}

Time

By default, the time is in epoch(unix) format. Changing formats are possible by specifying the format using the query param format.

Possible formats are:

  • epoch
  • iso8601

GET /util/time/now?format=[string](optional)&days=[int](optional)

Get the current timestamp (NOW) in UTC.

Query param days can be used to get a timestamp shifted by the number of days relative to NOW. The default value is 0.

Example: https://publicrest.co/util/time/now?days=-1

Output:

{"format":"epoch","time":1487386371}

GET /util/time/ytd?format=[string](optional)

Get yesterday's timestamp (exactly 1 day before NOW) in UTC.

Output:

{"format":"epoch","time":1487300560}

GET /util/time/tmr?format=[string](optional)

Get tomorrow's timestamp (exactly 1 day after NOW) in UTC.

Output:

{"format":"epoch","time":1487473371}

Cache

The cache service is backed by a redis instance, and the maximum TTL is 3600.

POST /util/cache/set

Save a value to the cache.

Input:

{"value":"Hello","ttl":60}

Output:

{"token":"897b9e50ab","ttl":60}

GET /util/cache/set?value=[string]&ttl=[int]

Save a value to the cache. This is the GET analog of the above POST request.

Example: https://publicrest.co/util/cache/set?value=Hello&ttl=60

Output:

{"token":"897b9e50ab","ttl":60}

GET /util/cache/get?token=[string]

Get the value cached on the server using the token returned by the POST call.

Output:

{"value":"Hello"}

Web Request

GET /util/web/ua

Get the user agent from the request.

Output:

{"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"}

GET /util/web/headers?pretty=[boolean](optional)

Get all headers from the request.

Output:

{
  "Connection": "keep-alive",
  "Accept": "text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8",
  "Accept-Language": "en-US, en;q=0.8",
  "Accept-Encoding": "gzip, deflate, sdch, br",
  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36",
}

publicrest's People

Contributors

laxenade avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.