The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,481 other followers

JSONPlaceholder – Fake online REST API for developers

Posted by jpluimers on 2021/03/25

A great way for testing REST JSON calls is using the [WayBack] JSONPlaceholder – Fake online REST API for developers:

Fake Online REST API for Testing and Prototyping
Serving ~200M requests per month
Powered by JSON Server [WayBack] + LowDB [WayBack]

It is like [WayBack] Placeholder.com: Placeholder Images Done For You [JPG, GIF & PNG] but for JSON and supports both CORS and JSON-P for cross domain requests.

You can either use that site (which has a predefined set of REST calls) or the basic [WayBack] My JSON Server – Fake online REST server for teams that allows you to respond it to a db.json file from github:

Fake Online REST server for teams

Create a JSON file on GitHub

github.com/user/repo/master/db.json
{
  "posts": [
    {
      "id": 1,
      "title": "hello"
    }
  ],
  "profile": {
    "name": "typicode"
  }
}

Get instantly a fake server

my-json-server.typicode.com/user/repo/posts/1
{
  "id": 1,
  "title": "hello"
}

Related

Documentation

There is basic documentation at the repository [WayBack] GitHub – typicode/jsonplaceholder: A simple online fake REST API server:

Features

  • No registration
  • Zero-config
  • Basic API
  • “Has many” relationships
  • Filters and nested resources
  • Cross-domain (CORS and JSONP)
  • Supports GET, POST, PUT, PATCH, DELETE and OPTIONS verbs
  • HTTP or HTTPS
  • Compatible with React, Angular, Vue, Ember, …

Available resources

Let’s start with resources, JSONPlaceholder provides the usual suspects:

How to

Here’s some code using Fetch API showing what can be done with JSONPlaceholder…

More documentation is at [WayBack] Example API Guide for the JSON Placeholder API.

Via

I learned about it during the great [WayBack] 2019 Spring4D Conference where [WayBack] gabr42 (Primož Gabrijelčič) · GitHub demonstrated how to write a JSON REST client by just defining a Delphi interface, and have a few clever classes based on the Spring4D VirtualInterface support (which also supports Delphi XE and 2010 in addition to the normal [WayBack] Delphi RTTI VirtualInterface support) translate them into JSON REST calls doing all the mapping to the call and from the result.

–jeroen

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 
%d bloggers like this: