title
PHP REST API From Scratch [2] - Single & Create

description
In this part of the series we will add functionality to fetch single posts as well as make a POST request to add posts Code: https://github.com/bradtraversy/php_rest_myblog 💖 Become a Patron: Show support & get perks! http://www.patreon.com/traversymedia Website & Udemy Courses http://www.traversymedia.com Follow Traversy Media: http://www.facebook.com/traversymedia http://www.twitter.com/traversymedia http://www.instagram.com/traversymedia

detail
{'title': 'PHP REST API From Scratch [2] - Single & Create', 'heatmap': [{'end': 348.01, 'start': 313.033, 'weight': 1}, {'end': 601.011, 'start': 566.502, 'weight': 0.712}, {'end': 1396.776, 'start': 1324.743, 'weight': 0.72}, {'end': 1458.549, 'start': 1425.276, 'weight': 0.75}], 'summary': "Learn to create a rest api with php, utilizing pdo's bind param for querying single posts, binding parameters for query execution, using ternary operator for condition-based value assignment, implementing error handling, and handling posted data to successfully add a post through the api.", 'chapters': [{'end': 170.144, 'segs': [{'end': 24.178, 'src': 'embed', 'start': 0.586, 'weight': 2, 'content': [{'end': 7.089, 'text': 'Alright, guys, welcome to part two of creating a REST API with just pure PHP, no frameworks or anything.', 'start': 0.586, 'duration': 6.503}, {'end': 9.951, 'text': 'in the last video we set up our core structure.', 'start': 7.089, 'duration': 2.862}, {'end': 16.294, 'text': 'we set up our database class, we set up our post model and we created the read function,', 'start': 9.951, 'duration': 6.343}, {'end': 24.178, 'text': 'and then we created our read dot PHP file to basically use the model to query the database and get the data,', 'start': 16.294, 'duration': 7.884}], 'summary': 'Creating a rest api with pure php, including database setup and read function.', 'duration': 23.592, 'max_score': 0.586, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-nq4UbD0NT8/pics/-nq4UbD0NT8586.jpg'}, {'end': 89.129, 'src': 'embed', 'start': 52.111, 'weight': 0, 'content': [{'end': 59.898, 'text': "So models post dot PHP and we're going to go right under the read function or method we created.", 'start': 52.111, 'duration': 7.787}, {'end': 67.844, 'text': "Make sure you're still within the class and let's say get single post.", 'start': 59.958, 'duration': 7.886}, {'end': 74.95, 'text': "So let's do public function single post.", 'start': 69.285, 'duration': 5.665}, {'end': 79.466, 'text': "or not single post, let's say read single.", 'start': 77.426, 'duration': 2.04}, {'end': 89.129, 'text': 'Since the first one was called read, and then the query is going to be pretty similar.', 'start': 81.487, 'duration': 7.642}], 'summary': 'Adding a method getsinglepost() within the php class models with a similar query as the read method.', 'duration': 37.018, 'max_score': 52.111, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-nq4UbD0NT8/pics/-nq4UbD0NT852111.jpg'}, {'end': 139.819, 'src': 'embed', 'start': 112.037, 'weight': 1, 'content': [{'end': 118.101, 'text': "So we're going to say where p.id equals question mark.", 'start': 112.037, 'duration': 6.064}, {'end': 125.086, 'text': "All right, now this question mark I'm using because we're going to use PDO's bind param.", 'start': 118.741, 'duration': 6.345}, {'end': 128.668, 'text': "We're basically going to bind something to this later on.", 'start': 125.106, 'duration': 3.562}, {'end': 130.089, 'text': "So it's basically a placeholder.", 'start': 128.708, 'duration': 1.381}, {'end': 131.871, 'text': "And what we're going to bind is the ID.", 'start': 130.209, 'duration': 1.662}, {'end': 137.397, 'text': "and then let's just say limit zero, one.", 'start': 132.935, 'duration': 4.462}, {'end': 139.819, 'text': 'So we just wanna get one record.', 'start': 137.457, 'duration': 2.362}], 'summary': "Using pdo's bind param to query one record with p.id as placeholder.", 'duration': 27.782, 'max_score': 112.037, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-nq4UbD0NT8/pics/-nq4UbD0NT8112037.jpg'}], 'start': 0.586, 'title': 'Creating a rest api with php', 'summary': "Delves into creating a rest api with pure php, including setting up a post model with read and read single functions, and utilizing pdo's bind param for querying single posts.", 'chapters': [{'end': 170.144, 'start': 0.586, 'title': 'Creating a rest api with php', 'summary': "Discusses setting up a rest api with pure php, creating a post model with read and read single functions, and using pdo's bind param for querying single posts.", 'duration': 169.558, 'highlights': ['The chapter focuses on setting up a REST API with pure PHP. Discussed the process of setting up a REST API without using any frameworks or external libraries.', 'The chapter includes creating a post model with read and read single functions. Covered the creation of a post model with read and read single functions to interact with the database and retrieve data.', "The chapter explains using PDO's bind param for querying single posts. Explained the utilization of PDO's bind param to bind the ID as a placeholder in the query for retrieving a single post."]}], 'duration': 169.558, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-nq4UbD0NT8/pics/-nq4UbD0NT8586.jpg', 'highlights': ['The chapter includes creating a post model with read and read single functions. Covered the creation of a post model with read and read single functions to interact with the database and retrieve data.', "The chapter explains using PDO's bind param for querying single posts. Explained the utilization of PDO's bind param to bind the ID as a placeholder in the query for retrieving a single post.", 'The chapter focuses on setting up a REST API with pure PHP. Discussed the process of setting up a REST API without using any frameworks or external libraries.']}, {'end': 370.066, 'segs': [{'end': 207.52, 'src': 'embed', 'start': 170.144, 'weight': 0, 'content': [{'end': 179.007, 'text': "so, while we're still in the read single, we want to now prepare our statement, and this will actually be the same as what we did up here.", 'start': 170.144, 'duration': 8.863}, {'end': 182.508, 'text': 'so we can actually copy it.', 'start': 179.007, 'duration': 3.501}, {'end': 183.929, 'text': 'so paste that in.', 'start': 182.508, 'duration': 1.421}, {'end': 190.839, 'text': "now we want to bind the ID to this right here, because right now it's just a question mark.", 'start': 183.929, 'duration': 6.91}, {'end': 199.354, 'text': 'So to do that we can say statement bind param.', 'start': 191.52, 'duration': 7.834}, {'end': 207.52, 'text': 'And we want the basically this is a positional parameter in PDO.', 'start': 201.438, 'duration': 6.082}], 'summary': 'Preparing statement for id binding in pdo.', 'duration': 37.376, 'max_score': 170.144, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-nq4UbD0NT8/pics/-nq4UbD0NT8170144.jpg'}, {'end': 348.01, 'src': 'heatmap', 'start': 268.445, 'weight': 1, 'content': [{'end': 275.25, 'text': 'And we want to fetch an associative array so PDO double underscore fetch underscore soc.', 'start': 268.445, 'duration': 6.805}, {'end': 283.256, 'text': 'And then we want to set the properties to whatever is returned.', 'start': 277.051, 'duration': 6.205}, {'end': 292.062, 'text': 'So we want for instance this title to equal row title.', 'start': 283.756, 'duration': 8.306}, {'end': 294.844, 'text': "Alright and I'll just copy these down.", 'start': 293.363, 'duration': 1.481}, {'end': 298.14, 'text': "We'll do 2, 3, 4, 5.", 'start': 294.864, 'duration': 3.276}, {'end': 301.783, 'text': "And then what I'll do is highlight this title here and do control D.", 'start': 298.14, 'duration': 3.643}, {'end': 304.245, 'text': "That'll take the next one and we'll say body.", 'start': 301.783, 'duration': 2.462}, {'end': 306.087, 'text': 'All right.', 'start': 304.265, 'duration': 1.822}, {'end': 307.568, 'text': "We'll do the same thing here.", 'start': 306.107, 'duration': 1.461}, {'end': 310.07, 'text': 'So this will be author.', 'start': 308.169, 'duration': 1.901}, {'end': 313.013, 'text': 'So title body author.', 'start': 311.571, 'duration': 1.442}, {'end': 320.519, 'text': 'We also want category ID and we also want category name.', 'start': 313.033, 'duration': 7.486}, {'end': 327.317, 'text': 'Okay, and that should do it as far as this read single method goes.', 'start': 323.112, 'duration': 4.205}, {'end': 339.77, 'text': "So we'll save this and now we're going to go to our post, our API post folder and create a new file called read underscore single dot PHP.", 'start': 328.037, 'duration': 11.733}, {'end': 348.01, 'text': 'All right, now, again, this is going to have a lot of the same stuff that our read.php had.', 'start': 341.766, 'duration': 6.244}], 'summary': 'Creating a php script to fetch and set properties for a single post, including title, body, author, category id, and category name.', 'duration': 71.325, 'max_score': 268.445, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-nq4UbD0NT8/pics/-nq4UbD0NT8268445.jpg'}], 'start': 170.144, 'title': 'Using pdo in php', 'summary': 'Covers binding parameters in pdo for query execution, emphasizing positional parameters and the need to bind the id. it also discusses using pdo to fetch and assign database query results, and creating a read single method in php.', 'chapters': [{'end': 233.356, 'start': 170.144, 'title': 'Binding parameters in pdo', 'summary': 'Covers the process of preparing and binding parameters in pdo for executing a query, emphasizing the usage of positional parameters and the need to bind the id to the statement.', 'duration': 63.212, 'highlights': ['Binding the ID to the statement using positional parameters in PDO, emphasizing the need to bind the ID to the statement.', 'Preparation of statement and copying the previous content for the statement preparation in PDO.', 'Usage of bind param to bind the ID to the statement in PDO.']}, {'end': 306.087, 'start': 235.058, 'title': 'Using pdo to fetch and assign database query results', 'summary': 'Discusses using pdo to fetch a single record array from a database query and assigning its properties, such as title and body, to the returned values.', 'duration': 71.029, 'highlights': ['Using PDO to fetch a single record array and assign its properties like title and body to the returned values', 'Executing a query and fetching an associative array using PDO double underscore fetch underscore soc', 'Assigning properties like title and body to the returned values from the database query']}, {'end': 370.066, 'start': 306.107, 'title': 'Creating read single method', 'summary': 'Discusses creating a new php file called read_single.php, which includes similar content to read.php and extracts the id from the url.', 'duration': 63.959, 'highlights': ['Creating a new PHP file called read_single.php', 'Including similar content to read.php', 'Extracting the ID from the URL']}], 'duration': 199.922, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-nq4UbD0NT8/pics/-nq4UbD0NT8170144.jpg', 'highlights': ['Binding the ID to the statement using positional parameters in PDO, emphasizing the need to bind the ID to the statement.', 'Using PDO to fetch a single record array and assign its properties like title and body to the returned values', 'Creating a new PHP file called read_single.php']}, {'end': 902.545, 'segs': [{'end': 394.273, 'src': 'embed', 'start': 372.572, 'weight': 5, 'content': [{'end': 381.641, 'text': "so let's say post will set the ID and we want to do a conditional here, but I'm going to use the ternary operator.", 'start': 372.572, 'duration': 9.069}, {'end': 382.862, 'text': "so it's like a shorthand.", 'start': 381.641, 'duration': 1.221}, {'end': 390.75, 'text': 'if and we also want to use is set okay, is set will check to see if a parameter, if something is set.', 'start': 382.862, 'duration': 7.888}, {'end': 393.132, 'text': 'now we want to use this money sign.', 'start': 390.75, 'duration': 2.382}, {'end': 394.273, 'text': 'get super global.', 'start': 393.132, 'duration': 1.141}], 'summary': 'Using the ternary operator to check if a parameter is set in a php script.', 'duration': 21.701, 'max_score': 372.572, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-nq4UbD0NT8/pics/-nq4UbD0NT8372572.jpg'}, {'end': 449.196, 'src': 'embed', 'start': 420.877, 'weight': 0, 'content': [{'end': 430.4, 'text': "So we're going to say if that's set, then, okay, question mark, we're using the ternary operator, then we just want to say get ID.", 'start': 420.877, 'duration': 9.523}, {'end': 431.78, 'text': 'We want to set it to that.', 'start': 430.56, 'duration': 1.22}, {'end': 436.05, 'text': 'else. so we use a colon for else.', 'start': 433.909, 'duration': 2.141}, {'end': 442.493, 'text': 'then we just want to call the die function, which basically just cuts everything off and and nothing will display or happen.', 'start': 436.05, 'duration': 6.443}, {'end': 444.514, 'text': "so it'll look for the get id.", 'start': 442.493, 'duration': 2.021}, {'end': 449.196, 'text': "if it's there, it'll get put into the post id.", 'start': 444.514, 'duration': 4.682}], 'summary': 'Using ternary operator to set post id if get id is present.', 'duration': 28.319, 'max_score': 420.877, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-nq4UbD0NT8/pics/-nq4UbD0NT8420877.jpg'}, {'end': 622.303, 'src': 'heatmap', 'start': 566.502, 'weight': 1, 'content': [{'end': 574.849, 'text': "So we'll have the post array, but we want to wrap it in JSON underscore in code.", 'start': 566.502, 'duration': 8.347}, {'end': 583.487, 'text': 'Okay, so hopefully that works.', 'start': 581.607, 'duration': 1.88}, {'end': 584.428, 'text': "Let's save it.", 'start': 583.787, 'duration': 0.641}, {'end': 590.229, 'text': "Let's go to Postman and let's actually leave what we did here.", 'start': 585.448, 'duration': 4.781}, {'end': 594.77, 'text': "So it's going to be read underscore single dot PHP with the ID of three.", 'start': 590.309, 'duration': 4.461}, {'end': 596.97, 'text': "We'll send and there it is.", 'start': 595.61, 'duration': 1.36}, {'end': 601.011, 'text': 'So we just have a single object with all that data.', 'start': 597.65, 'duration': 3.361}, {'end': 606.032, 'text': "And if we do like one, we'll send and we get the post with one.", 'start': 601.631, 'duration': 4.401}, {'end': 611.719, 'text': "OK so now let's move on to where are we here.", 'start': 607.358, 'duration': 4.361}, {'end': 616.701, 'text': "Let's move on to creating a post.", 'start': 614.16, 'duration': 2.541}, {'end': 622.303, 'text': 'OK, so this will be a little different, will be a post request that we make from our API,', 'start': 617.401, 'duration': 4.902}], 'summary': 'Demonstrating how to retrieve and create posts using json in postman.', 'duration': 31.994, 'max_score': 566.502, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-nq4UbD0NT8/pics/-nq4UbD0NT8566502.jpg'}, {'end': 826.835, 'src': 'embed', 'start': 798.308, 'weight': 4, 'content': [{'end': 803.831, 'text': "We're just running the title through strip tags and through HTML special charts.", 'start': 798.308, 'duration': 5.523}, {'end': 806.472, 'text': "There's other ways to sanitize your data.", 'start': 803.911, 'duration': 2.561}, {'end': 809.473, 'text': 'This may not even be the best way.', 'start': 807.392, 'duration': 2.081}, {'end': 817.717, 'text': "There's so many and people argue over it all the time, but I'm not really going to get into super security and stuff like that.", 'start': 809.513, 'duration': 8.204}, {'end': 819.698, 'text': "For what we're doing here, this is fine.", 'start': 818.037, 'duration': 1.661}, {'end': 823.86, 'text': "Now, we're going to do this for two, three, four.", 'start': 820.799, 'duration': 3.061}, {'end': 826.835, 'text': 'more fields.', 'start': 826.055, 'duration': 0.78}], 'summary': 'Discussing data sanitization methods for multiple fields.', 'duration': 28.527, 'max_score': 798.308, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-nq4UbD0NT8/pics/-nq4UbD0NT8798308.jpg'}], 'start': 372.572, 'title': 'Using ternary operator and creating/reading posts in php api', 'summary': 'Explains using the ternary operator in php to check if a parameter is set and assign a value based on the condition, introducing die function. it also covers creating a post using a post request in the api, demonstrating how to read single posts and convert data to json, utilizing php and pdo for security and functionality.', 'chapters': [{'end': 449.196, 'start': 372.572, 'title': 'Using ternary operator for conditional check', 'summary': 'Explains how to use the ternary operator in php to check if a parameter is set and assign a value based on the condition, demonstrating the use of the is set function and the super global variable. it also introduces the die function for terminating execution.', 'duration': 76.624, 'highlights': ['Explaining the use of ternary operator for conditional check and shorthand assignment The transcript discusses using the ternary operator to conditionally set the ID and provides an example of shorthand assignment, demonstrating efficient coding practices.', 'Demonstrating the use of is set function to check if a parameter is set The chapter explains the use of the is set function to check if a parameter is set, showcasing practical usage of PHP functions for parameter validation.', 'Introducing the die function for terminating execution The transcript introduces the die function as a method to abruptly terminate execution, explaining its purpose in handling scenarios where certain conditions are not met.']}, {'end': 902.545, 'start': 449.196, 'title': 'Creating and reading posts in php api', 'summary': 'Covers creating a post using a post request in the api, demonstrating how to read single posts and convert data to json, utilizing php and pdo, with a focus on preparing and binding data for security and functionality.', 'duration': 453.349, 'highlights': ['Demonstrating how to create a post using a post request in the API The chapter demonstrates the process of creating a post using a post request in the API, showcasing the use of PHP and PDO for database operations.', 'Explaining the process of reading single posts and converting data to JSON The transcript explains the process of reading single posts and converting the retrieved data into JSON format, showcasing the functionality of the PHP code.', 'Emphasizing the importance of preparing and binding data for security The transcript emphasizes the importance of preparing and binding data for security by utilizing functions like HTML special chars and strip tags to sanitize the submitted data.']}], 'duration': 529.973, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-nq4UbD0NT8/pics/-nq4UbD0NT8372572.jpg', 'highlights': ['Introducing the die function for terminating execution The transcript introduces the die function as a method to abruptly terminate execution, explaining its purpose in handling scenarios where certain conditions are not met.', 'Explaining the process of reading single posts and converting data to JSON The transcript explains the process of reading single posts and converting the retrieved data into JSON format, showcasing the functionality of the PHP code.', 'Demonstrating how to create a post using a post request in the API The chapter demonstrates the process of creating a post using a post request in the API, showcasing the use of PHP and PDO for database operations.', 'Explaining the use of ternary operator for conditional check and shorthand assignment The transcript discusses using the ternary operator to conditionally set the ID and provides an example of shorthand assignment, demonstrating efficient coding practices.', 'Emphasizing the importance of preparing and binding data for security The transcript emphasizes the importance of preparing and binding data for security by utilizing functions like HTML special chars and strip tags to sanitize the submitted data.', 'Demonstrating the use of is set function to check if a parameter is set The chapter explains the use of the is set function to check if a parameter is set, showcasing practical usage of PHP functions for parameter validation.']}, {'end': 1143.889, 'segs': [{'end': 968.102, 'src': 'embed', 'start': 903.045, 'weight': 0, 'content': [{'end': 904.986, 'text': 'Then we need to execute our query.', 'start': 903.045, 'duration': 1.941}, {'end': 920.969, 'text': "So for this, we're just gonna say if Now remember, we're not returning data here, we're creating data, so I'm just going to do an if statement.", 'start': 909.268, 'duration': 11.701}, {'end': 931.556, 'text': 'So if statement execute, so basically if it executes and everything goes okay, we just want to return true.', 'start': 922.63, 'duration': 8.926}, {'end': 935.079, 'text': "Now if it doesn't, we want to return.", 'start': 932.997, 'duration': 2.082}, {'end': 938.787, 'text': "false, but if it doesn't, I want some extra data.", 'start': 935.666, 'duration': 3.121}, {'end': 944.168, 'text': 'so this is where, remember, we set the error mode to error mode, exception.', 'start': 938.787, 'duration': 5.381}, {'end': 953.151, 'text': "so we'll be able to print, say print error if something goes wrong.", 'start': 944.168, 'duration': 8.983}, {'end': 968.102, 'text': "so what I'm going to do is use a print F and we're going to say error and then put a %s, which is basically like a placeholder.", 'start': 953.151, 'duration': 14.951}], 'summary': 'Executing query to create data, returning true on success, false on failure, with error handling.', 'duration': 65.057, 'max_score': 903.045, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-nq4UbD0NT8/pics/-nq4UbD0NT8903045.jpg'}, {'end': 1074.828, 'src': 'embed', 'start': 1029.521, 'weight': 2, 'content': [{'end': 1036.527, 'text': 'So we want to put what methods we want to allow here, which is going to be just a post request.', 'start': 1029.521, 'duration': 7.006}, {'end': 1037.928, 'text': "So I'm going to say access.", 'start': 1036.627, 'duration': 1.301}, {'end': 1047.556, 'text': 'control allow methods and the value for this.', 'start': 1040.854, 'duration': 6.702}, {'end': 1051.497, 'text': 'The value is going to be post.', 'start': 1049.617, 'duration': 1.88}, {'end': 1053.298, 'text': 'All right.', 'start': 1052.998, 'duration': 0.3}, {'end': 1059, 'text': "And then I'm also going to put here the actual allowed header values.", 'start': 1053.358, 'duration': 5.642}, {'end': 1061.2, 'text': "So let's allow.", 'start': 1059.82, 'duration': 1.38}, {'end': 1064.401, 'text': 'Not allow access.', 'start': 1061.22, 'duration': 3.181}, {'end': 1068.322, 'text': 'Control allow.', 'start': 1067.602, 'duration': 0.72}, {'end': 1074.828, 'text': "headers, and then it's it's basically which.", 'start': 1071.727, 'duration': 3.101}], 'summary': 'Configuring access control for post request with allowed headers.', 'duration': 45.307, 'max_score': 1029.521, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-nq4UbD0NT8/pics/-nq4UbD0NT81029521.jpg'}, {'end': 1148.632, 'src': 'embed', 'start': 1116.631, 'weight': 4, 'content': [{'end': 1118.192, 'text': 'I still want it to be allowed.', 'start': 1116.631, 'duration': 1.561}, {'end': 1130.28, 'text': 'And then also we want this X dash requested with which will help with cross site scripting attacks.', 'start': 1118.612, 'duration': 11.668}, {'end': 1139.367, 'text': "And it also has to do with cores and stuff that I really don't want to get into, but I'm just going to put it here anyways,", 'start': 1132.423, 'duration': 6.944}, {'end': 1143.889, 'text': 'in case we do something else with this later, in case we build a front end or something.', 'start': 1139.367, 'duration': 4.522}, {'end': 1148.632, 'text': 'So that should be it for the headers, I believe, hopefully.', 'start': 1144.95, 'duration': 3.682}], 'summary': 'Request for x-dash to prevent cross-site scripting attacks and handle cores.', 'duration': 32.001, 'max_score': 1116.631, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-nq4UbD0NT8/pics/-nq4UbD0NT81116631.jpg'}], 'start': 903.045, 'title': 'Executing query and error handling and setting up http post request headers', 'summary': 'Details executing a query and implementing error handling in php using if statements and error mode settings. it also covers setting up http post request headers with specific header values to prevent cross site scripting attacks.', 'chapters': [{'end': 999.758, 'start': 903.045, 'title': 'Executing query and error handling', 'summary': 'Details the process of executing a query and implementing error handling in php, emphasizing the use of if statements and error mode settings, to ensure the return of true for successful execution and the handling of errors with specific error messages.', 'duration': 96.713, 'highlights': ['The process involves executing a query in PHP and using if statements to handle the execution, where a successful execution returns true, and an unsuccessful one returns false with additional error data.', 'Implementing error handling involves setting the error mode to exception and using print F to display error messages, ensuring the visibility of errors in the raw tab in Postman.']}, {'end': 1143.889, 'start': 1001.76, 'title': 'Setting up http post request headers', 'summary': 'Covers setting up http post request headers by adding specific header values including access control, allowed methods, allowed headers, content type, and authorization, to prevent cross site scripting attacks.', 'duration': 142.129, 'highlights': ["Adding access control allow methods for post request with the value 'post'.", 'Specifying allowed headers and methods to prevent cross site scripting attacks.', 'Including the X-requested-with header to mitigate cross site scripting attacks.']}], 'duration': 240.844, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-nq4UbD0NT8/pics/-nq4UbD0NT8903045.jpg', 'highlights': ['The process involves executing a query in PHP and using if statements to handle the execution, where a successful execution returns true, and an unsuccessful one returns false with additional error data.', 'Implementing error handling involves setting the error mode to exception and using print F to display error messages, ensuring the visibility of errors in the raw tab in Postman.', "Adding access control allow methods for post request with the value 'post'.", 'Specifying allowed headers and methods to prevent cross site scripting attacks.', 'Including the X-requested-with header to mitigate cross site scripting attacks.']}, {'end': 1499.587, 'segs': [{'end': 1258.227, 'src': 'embed', 'start': 1144.95, 'weight': 0, 'content': [{'end': 1148.632, 'text': 'So that should be it for the headers, I believe, hopefully.', 'start': 1144.95, 'duration': 3.682}, {'end': 1150.813, 'text': "And then we're going to go down here.", 'start': 1149.372, 'duration': 1.441}, {'end': 1158.536, 'text': "after where we instantiate our blog post object, and we need to get the data that's posted.", 'start': 1151.912, 'duration': 6.624}, {'end': 1168.383, 'text': "So when we make our request from Postman, we're going to add the title, the body, the author, and the category ID, and we need to get that.", 'start': 1158.877, 'duration': 9.506}, {'end': 1172.265, 'text': 'So we need to say get the raw posted data.', 'start': 1168.723, 'duration': 3.542}, {'end': 1175.479, 'text': "And there's a few ways to do that.", 'start': 1174.258, 'duration': 1.221}, {'end': 1181.502, 'text': "What we're going to do is we're going to say JSON decode because it's going to be in JSON format.", 'start': 1175.519, 'duration': 5.983}, {'end': 1186.584, 'text': 'And then we can say file get contents.', 'start': 1182.022, 'duration': 4.562}, {'end': 1195.068, 'text': "And then we're going to pass in here PHP colon double forward slash input.", 'start': 1187.885, 'duration': 7.183}, {'end': 1198.31, 'text': 'And that should get us whatever is submitted.', 'start': 1195.969, 'duration': 2.341}, {'end': 1206.62, 'text': "OK, so once we do that, let's assign what we have in the data to the post.", 'start': 1199.338, 'duration': 7.282}, {'end': 1210.681, 'text': 'So to the post model or post object, I should say.', 'start': 1207.64, 'duration': 3.041}, {'end': 1215.742, 'text': 'So post title will then equal data title.', 'start': 1210.781, 'duration': 4.961}, {'end': 1219.363, 'text': "OK, and we'll just copy this down three more times.", 'start': 1216.583, 'duration': 2.78}, {'end': 1222.164, 'text': "And we're also going to get the body.", 'start': 1220.404, 'duration': 1.76}, {'end': 1225.105, 'text': "We're going to get the author.", 'start': 1223.825, 'duration': 1.28}, {'end': 1233.722, 'text': "and we're going to get the category id.", 'start': 1227.558, 'duration': 6.164}, {'end': 1237.285, 'text': 'okay, so now we want to actually create the post.', 'start': 1233.722, 'duration': 3.563}, {'end': 1244.31, 'text': "so we're going to use the method that we created in the model, but i'm going to put it inside an if statement just in case it doesn't happen.", 'start': 1237.285, 'duration': 7.025}, {'end': 1247.192, 'text': 'then we can say whatever post not created.', 'start': 1244.31, 'duration': 2.882}, {'end': 1258.227, 'text': "so let's say post and then we'll call create which we just created, and then, if that happens, then let's echo json underscore and code,", 'start': 1247.192, 'duration': 11.035}], 'summary': 'Decoding and creating blog post data from json format, ensuring inclusion of title, body, author, and category id.', 'duration': 113.277, 'max_score': 1144.95, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-nq4UbD0NT8/pics/-nq4UbD0NT81144950.jpg'}, {'end': 1396.776, 'src': 'heatmap', 'start': 1324.743, 'weight': 0.72, 'content': [{'end': 1338.795, 'text': "Did I? What the hell? OK, what am I missing here? Oh, wait, I'm thinking we're in the class still.", 'start': 1324.743, 'duration': 14.052}, {'end': 1341.072, 'text': 'there we go.', 'start': 1340.051, 'duration': 1.021}, {'end': 1342.652, 'text': 'sorry about that.', 'start': 1341.072, 'duration': 1.58}, {'end': 1345.234, 'text': "i could cut that out, but i don't want to.", 'start': 1342.652, 'duration': 2.582}, {'end': 1346.254, 'text': "so let's try this out.", 'start': 1345.234, 'duration': 1.02}, {'end': 1350.556, 'text': "we're going to try to create a post through postman,", 'start': 1346.254, 'duration': 4.302}, {'end': 1366.084, 'text': "so we want to go to post slash create.php and we're going to change this to make sure you change it to a post request and we want to go to headers and we want to specify the content type.", 'start': 1350.556, 'duration': 15.528}, {'end': 1370.005, 'text': "So if we start to type content, we'll get this drop down.", 'start': 1366.665, 'duration': 3.34}, {'end': 1371.226, 'text': 'We want content type.', 'start': 1370.045, 'duration': 1.181}, {'end': 1374.206, 'text': 'We want application slash JSON.', 'start': 1371.746, 'duration': 2.46}, {'end': 1378.027, 'text': "Okay, remember in the header, that's what we accept.", 'start': 1375.167, 'duration': 2.86}, {'end': 1381.328, 'text': "That's what our API accepts.", 'start': 1378.367, 'duration': 2.961}, {'end': 1387.469, 'text': "And then the body, I'm gonna choose raw because I'm just gonna submit raw JSON.", 'start': 1382.028, 'duration': 5.441}, {'end': 1395.095, 'text': 'All right, so We want to put double quotes around both the keys and the values.', 'start': 1388.81, 'duration': 6.285}, {'end': 1396.776, 'text': "So let's do title.", 'start': 1395.475, 'duration': 1.301}], 'summary': 'The speaker discusses using postman to create a post request, specifying content type as application/json and formatting the request body with double quotes.', 'duration': 72.033, 'max_score': 1324.743, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-nq4UbD0NT8/pics/-nq4UbD0NT81324743.jpg'}, {'end': 1458.549, 'src': 'heatmap', 'start': 1425.276, 'weight': 0.75, 'content': [{'end': 1434.842, 'text': 'And then we want category ID which one I believe is technology.', 'start': 1425.276, 'duration': 9.566}, {'end': 1435.543, 'text': 'All right.', 'start': 1435.362, 'duration': 0.181}, {'end': 1436.523, 'text': "So let's try this out.", 'start': 1435.563, 'duration': 0.96}, {'end': 1438.765, 'text': "We'll send we get post created.", 'start': 1436.563, 'duration': 2.202}, {'end': 1439.705, 'text': "That's a good sign.", 'start': 1438.825, 'duration': 0.88}, {'end': 1444.168, 'text': 'Now we could we could check this a few ways.', 'start': 1440.286, 'duration': 3.882}, {'end': 1448.751, 'text': 'We could just make another get request to post read.', 'start': 1444.228, 'duration': 4.523}, {'end': 1458.549, 'text': "dot php, that'll, that'll give us all of our posts, and there it is my tech posts.", 'start': 1453.387, 'duration': 5.162}], 'summary': 'Successfully created a technology post and confirmed its existence by making a get request to retrieve all posts.', 'duration': 33.273, 'max_score': 1425.276, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-nq4UbD0NT8/pics/-nq4UbD0NT81425276.jpg'}, {'end': 1499.587, 'src': 'embed', 'start': 1477.252, 'weight': 1, 'content': [{'end': 1483.616, 'text': 'My tech post ID seven category ID sample post got the author, the created at.', 'start': 1477.252, 'duration': 6.364}, {'end': 1484.477, 'text': 'So there we go.', 'start': 1484.016, 'duration': 0.461}, {'end': 1487.919, 'text': 'We successfully have added a post through our API.', 'start': 1484.557, 'duration': 3.362}, {'end': 1489.72, 'text': 'All right, guys.', 'start': 1488.059, 'duration': 1.661}, {'end': 1493.263, 'text': 'So I think that this is a good place to stop in the next video.', 'start': 1489.74, 'duration': 3.523}, {'end': 1499.587, 'text': 'What I want to do is start to work on being able to update posts and also being able to delete them.', 'start': 1493.323, 'duration': 6.264}], 'summary': 'Successfully added a post through api, aiming to work on updating and deleting posts in the next video.', 'duration': 22.335, 'max_score': 1477.252, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-nq4UbD0NT8/pics/-nq4UbD0NT81477252.jpg'}], 'start': 1144.95, 'title': 'Handling posted data, creating post object, and creating post through api in php', 'summary': 'Covers handling posted data in php, extracting title, body, author, and category id, using json decode and file get contents. it also explains creating a post object in php, involving error handling and echoing json content, and creating a post through an api using postman, resulting in successful addition of a post with id seven under the technology category.', 'chapters': [{'end': 1206.62, 'start': 1144.95, 'title': 'Handling posted data in php', 'summary': 'Covers handling posted data in php, including extracting title, body, author, and category id from a request, and using json decode and file get contents to process the submitted data.', 'duration': 61.67, 'highlights': ['The chapter covers handling posted data in PHP, including extracting title, body, author, and category ID from a request.', 'The method involves using JSON decode and file get contents to process the submitted data.']}, {'end': 1341.072, 'start': 1207.64, 'title': 'Creating a post object in php', 'summary': 'Explains creating a post object in php, involving getting post title, body, author, and category id, using if-else statements for error handling, and echoing json content for successful and unsuccessful post creation.', 'duration': 133.432, 'highlights': ['Using if-else statements for error handling when creating a post object in PHP, ensuring proper execution and error messages.', 'Explaining the difference between dealing with JSON in PHP and JavaScript, highlighting the additional steps required in PHP for encoding arrays as JSON.', 'Detailing the process of getting post title, body, author, and category id for creating a post object in PHP, emphasizing the key data points involved.', 'Demonstrating the usage of the create method in the model to create a post object in PHP, providing a practical implementation of the concept.']}, {'end': 1499.587, 'start': 1341.072, 'title': 'Creating post through api', 'summary': 'Discusses the process of creating a post through an api using postman, including specifying headers and sending a raw json body, resulting in the successful addition of a post with id seven under the technology category.', 'duration': 158.515, 'highlights': ['The process of creating a post through an API using Postman is demonstrated, including specifying headers and sending a raw JSON body.', "A post with the title 'My Tech Post' and content 'This is a sample post' is successfully added, with an ID of seven and under the technology category.", 'The ID of the newly added post is seven, as the last one was six, and the ID is auto-incremented.', 'The chapter concludes with a plan to work on updating and deleting posts in the next video.']}], 'duration': 354.637, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/-nq4UbD0NT8/pics/-nq4UbD0NT81144950.jpg', 'highlights': ['The process of creating a post through an API using Postman is demonstrated, including specifying headers and sending a raw JSON body.', "A post with the title 'My Tech Post' and content 'This is a sample post' is successfully added, with an ID of seven and under the technology category.", 'Using if-else statements for error handling when creating a post object in PHP, ensuring proper execution and error messages.', 'The chapter covers handling posted data in PHP, including extracting title, body, author, and category ID from a request.', 'The method involves using JSON decode and file get contents to process the submitted data.']}], 'highlights': ['The process of creating a post through an API using Postman is demonstrated, including specifying headers and sending a raw JSON body.', "A post with the title 'My Tech Post' and content 'This is a sample post' is successfully added, with an ID of seven and under the technology category.", 'The chapter covers handling posted data in PHP, including extracting title, body, author, and category ID from a request.', 'The method involves using JSON decode and file get contents to process the submitted data.', 'The process involves executing a query in PHP and using if statements to handle the execution, where a successful execution returns true, and an unsuccessful one returns false with additional error data.', 'Implementing error handling involves setting the error mode to exception and using print F to display error messages, ensuring the visibility of errors in the raw tab in Postman.', "Adding access control allow methods for post request with the value 'post'.", 'Specifying allowed headers and methods to prevent cross site scripting attacks.', 'Including the X-requested-with header to mitigate cross site scripting attacks.', 'Demonstrating the use of is set function to check if a parameter is set The chapter explains the use of the is set function to check if a parameter is set, showcasing practical usage of PHP functions for parameter validation.', 'Explaining the use of ternary operator for conditional check and shorthand assignment The transcript discusses using the ternary operator to conditionally set the ID and provides an example of shorthand assignment, demonstrating efficient coding practices.', 'Emphasizing the importance of preparing and binding data for security The transcript emphasizes the importance of preparing and binding data for security by utilizing functions like HTML special chars and strip tags to sanitize the submitted data.', 'Demonstrating how to create a post using a post request in the API The chapter demonstrates the process of creating a post using a post request in the API, showcasing the use of PHP and PDO for database operations.', 'Explaining the process of reading single posts and converting data to JSON The transcript explains the process of reading single posts and converting the retrieved data into JSON format, showcasing the functionality of the PHP code.', 'Introducing the die function for terminating execution The transcript introduces the die function as a method to abruptly terminate execution, explaining its purpose in handling scenarios where certain conditions are not met.', 'Binding the ID to the statement using positional parameters in PDO, emphasizing the need to bind the ID to the statement.', 'Using PDO to fetch a single record array and assign its properties like title and body to the returned values', 'Creating a new PHP file called read_single.php', 'The chapter includes creating a post model with read and read single functions. Covered the creation of a post model with read and read single functions to interact with the database and retrieve data.', "The chapter explains using PDO's bind param for querying single posts. Explained the utilization of PDO's bind param to bind the ID as a placeholder in the query for retrieving a single post.", 'The chapter focuses on setting up a REST API with pure PHP. Discussed the process of setting up a REST API without using any frameworks or external libraries.']}