Todos - Update API

Update the specified Todo.

Method PUT

Parameters

Name Details Type Required
id The ID of the Todo. integer Yes
title The title of the Todo. string No
completed The completion status of the Todo. boolean No

Body

{
    "title": "string",
    "completed": "boolean",
    "user_id": "integer",
    "description": "string"
}

How to Use

fetch('https://simplecrudapi.com/api/todos/1', {
	method: 'PUT', 
	headers: {
		'Content-Type': 'application/json'
	},
	body: JSON.stringify({
		title: '',
		description: '',
		completed: '',
		user_id: ''
	})
})
	.then(response => response.json())
	.then(json => console.log(json))
	.catch(error => console.error('Error updating data:', error));

Response

{
    "data": {
        "id": 1,
        "title": "Updated Todo",
        "description": "Updated description of the todo item",
        "completed": false,
        "user": {
            "id": 1,
            "name": "Jhon Doe",
            "email": "jhondoe@example.com",
            "email_verified_at": "2019-08-24T14:15:22Z",
            "created_at": "2019-08-24T14:15:22Z",
            "updated_at": "2019-11-09T12:00:00Z"
        },
        "created_at": "2019-08-24T14:15:22Z",
        "updated_at": "2019-11-09T12:00:00Z"
    }
}

Error Responses

{
    "message": "The given data was invalid.",
    "errors": {
        "user_id": [
            "The user id must be an integer.",
            "The selected user id is invalid."
        ],
        "title": [
            "The title field is required.",
            "The title must be a string.",
            "The title must be at least 1 character."
        ],
        "description": [
            "The description must be a string."
        ],
        "completed": [
            "The completed field is required.",
            "The completed field must be true or false."
        ]
    }
}

Try Now

fetch('https://simplecrudapi.com/api/todos/1', {
	method: 'PUT', 
	headers: {
		'Content-Type': 'application/json'
	},
	body: JSON.stringify({
		title: '',
		description: '',
		completed: '',
		user_id: ''
	})
})
	.then(response => response.json())
	.then(json => console.log(json))
	.catch(error => console.error('Error updating data:', error));

Test with Open API

View Open API

Our Proudly Sponsors 🎉

© 2024 Simple CRUD API. All rights reserved.