Skip to content

An open demo REST API to build demos on, test stuff against or just play around with.

License

Notifications You must be signed in to change notification settings

zekroTJA/example-rest-api

Repository files navigation

Example REST API

An open source CRUD REST API to build demos on, test stuff against or just play around with.

Motivation

For other projects, I was using restful-api.dev to build demos or tests on. But recently, this page proved to be somewhat inconsistent and unreliable, so I wanted to build something hosted on Vercel using Upstash as Redis Store, so that it should be a pretty reliable alternative.

API Documentation

The live API root endpoint is as following.

https://example-rest-api.vercel.app

The API accepts request payloads as application/json and responses are encoded in application/json.

Warning
Created objects are not persistent nor protected. Objects are usually automatically removed 24 hours after creation or modification. Objects and collection are not proof against modification by unauthorized individuals.

Objects

Collection

type CollectionRequest = {
    name: string;
};

type CollectionResponse = {
    id: string;
    created_at: string; // Format: RFC3339
    name: string;
};

Object

type ObjectRequest = {
    name: string;
    data: { [key: string]: any };
};

type ObjectResponse = {
    id: string;
    created_at: string; // Format: RFC3339
    name: string;
    data: { [key: string]: any };
};

Endpoints

Create Collection

Create a new collection.

POST /api/collections
Request Payload
CollectionRequest

Example:

{
    "name": "my games"
}
Response Payload
CollectionResponse

Example:

{
	"id": "chf13ur2iejc717547r0",
	"created_at": "2023-05-12T10:16:27.319442753+00:00",
	"name": "my games"
}

Get Collection

Retrieve information about a collection by ID.

GET /api/collections/:collectionid
Response Payload
CollectionResponse

Example:

{
	"id": "chf13ur2iejc717547r0",
	"created_at": "2023-05-12T10:16:27.319442753+00:00",
	"name": "my games"
}

Update Collection

Update a collection.

POST /api/collections/:collectionid
Request Payload
CollectionRequest

Example:

{
    "name": "My Games"
}
Response Payload
CollectionResponse

Example:

{
	"id": "chf13ur2iejc717547r0",
	"created_at": "2023-05-12T10:16:27.319442753+00:00",
	"name": "My Games"
}

Delete Collection

Delete a collection by ID.

DELETE /api/collections/:collectionid

Create Object

Create a new object in a collection.

POST /api/collections/:collectionid/objects
Request Payload
ObjectRequest

Example:

{
    "name": "Cyberpunk 2077",
    "data": {
        "publisher": "CD PROJECT RED",
        "developer": "CD PROJECT RED",
        "released": "2020-12-10T00:00:00Z",
        "tags": ["Cyberpunk", "Open World", "RPG", "Sci-fi"],
        "age_rating": "18"
    }
}
Response Payload
ObjectResponse

Example:

{
	"id": "chf15eacaqvs715h7ae0",
	"created_at": "2023-05-12T10:19:37.971387217+00:00",
	"name": "Cyberpunk 2077",
	"data": {
		"tags": [
			"Cyberpunk",
			"Open World",
			"RPG",
			"Sci-fi"
		],
		"age_rating": "18",
		"publisher": "CD PROJECT RED",
		"developer": "CD PROJECT RED",
		"released": "2020-12-10T00:00:00Z"
	}
}

Get Object

Retrieve an object from a collection by ID.

GET /api/collections/:collectionid/objects/:objectid
Response Payload
ObjectResponse

Example:

{
	"id": "chf15eacaqvs715h7ae0",
	"created_at": "2023-05-12T10:19:37.971387217+00:00",
	"name": "Cyberpunk 2077",
	"data": {
		"tags": [
			"Cyberpunk",
			"Open World",
			"RPG",
			"Sci-fi"
		],
		"age_rating": "18",
		"publisher": "CD PROJECT RED",
		"developer": "CD PROJECT RED",
		"released": "2020-12-10T00:00:00Z"
	}
}

Update Object

Update an object in a collection.

POST /api/collections/:collectionid/objects/:objectid
Request Payload
ObjectRequest

Example:

{
    "name": "Cyberpunk 2077",
    "data": {
        "publisher": "CD PROJECT RED",
        "developer": "CD PROJECT RED",
        "released": "2020-12-10T00:00:00Z",
        "tags": ["Cyberpunk", "Open World", "RPG", "Sci-fi", "Explicit"],
        "age_rating": "18"
    }
}

Delete Object

Delete an object in a collection by ID.

DELETE /api/collections/:collectionid/objects/:objectid

© 2023 Ringo Hoffmann.
Covered by the MIT License.

About

An open demo REST API to build demos on, test stuff against or just play around with.

Topics

Resources

License

Stars

Watchers

Forks

Languages