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
- [WayBack] typicode · GitHub
- [WayBack] GitHub – typicode/json-server: Get a full fake REST API with zero coding in less than 30 seconds (seriously)
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:
- Posts https://jsonplaceholder.typicode.com/posts/1
- Comments https://jsonplaceholder.typicode.com/comments/1
- Albums https://jsonplaceholder.typicode.com/albums/1
- Photos https://jsonplaceholder.typicode.com/photos/1
- Users https://jsonplaceholder.typicode.com/users/1
- Todos https://jsonplaceholder.typicode.com/todos/1
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