A Free REST API Service

A free REST API service for making HTTP requests that returns real data in JSON format.

Requests of type GET, POST, PUT and DELETE are supported.

Endpoints

/get

Returns all posts:

fetch('https://api.openjavascript.info/get')
.then(res => res.json())
.then(data => console.log(data))
.catch(err => console.log(err))

// [
//   {
//     "postId": 0,
//     "authorId": 10,
//     "img": "https://via.placeholder.com/600/527390",
//     "thumbnail": "https://via.placeholder.com/600/456827",
//     "title": "elit laboris ea nisi esse",
//     "body": "Culpa elit nulla exercitation adipisicing laborum..."
//   },
//   {
//     "postId": 1,
//     "authorId": 9,
//     "img": "https://via.placeholder.com/600/438696",
//     "thumbnail": "https://via.placeholder.com/600/407558",
//     "title": "voluptate et incididunt dolore labore",
//     "body": "Fugiat commodo nulla voluptate cupidatat do eu nisi..."
//   }
//   ...
// ]

/get/postId

Returns post with specified postId:

fetch('https://api.openjavascript.info/get/1')
.then(res => res.json())
.then(data => console.log(data))
.catch(err => console.log(err)


// {
//   "postId": 1,
//   "authorId": 5,
//   "img": "https://via.placeholder.com/600/774438",
//   "thumbnail": "https://via.placeholder.com/600/238942",
//   "title": "cupidatat est ea pariatur cillum",
//   "body": "Ex ad Lorem irure velit esse commodo..."
// }

/post

Creates a new post with a given title and body:

fetch('https://api.openjavascript.info/post', {
    method: "POST",
    body: JSON.stringify({
        title: "New one",
        body: "Some text",
    }),
    headers: { "Content-type": "application/json" }
})
.then(res => res.json())
.then(data => console.log(data))
.catch(err => console.log(err)

// {
//   "status": "New article created!",
//   "createdTimestamp": 1677054393804,
//   "userId": 3,
//   "postId": 2,
//   "title": "New one",
//   "body": "Some text"
// }

/put/postId

Updates post with given with specified postId:

fetch('https://api.openjavascript.info/put/1', {
    method: "PUT",
    body: JSON.stringify({
        title: "New text",
        body: "Altered text",
    }),
    headers: { "Content-type": "application/json" }
})
.then(res => res.json())
.then(data => console.log(data))
.catch(err => console.log(err))

// {
//   "status": "Post updated!",
//   "timestamp": 1677057304292,
//   "title": "New text",
//   "body": "Altered text"
// }

/delete/postId

Delete post with specified postId:

fetch('https://api.openjavascript.info/delete/1', {
    method: "DELETE",
})
.then(res => res.json())
.then(data => console.log(data))
.catch(err => console.log(err))

// {
//   "status": "Success! Post with the ID 1 was deleted",
//   "timestamp": 1677057446957
// }

Related posts