Flat 10% off on the purchase of any two apps or more. Use coupon code - FESTIVAL10
Native Shopify Mobile App with 20 new features
Kickstart your hyperlocal marketplace in Corona pandemic with a starter guide
Android App Development
iOS App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 184.108.40.206 release ready!
Owner and Founder. Opencart
Today we are going to create a Post API in symfony. Here I assume that you have a active symfony project thats already connected to database if you don’t have a project create one and connect it to a database by either creating a new one or connecting your project to existing database. So lets start with our project.
Firstly create a new controller in your bundle as I did with the name NewController.php and create a fuction in it with any name but having suffix as ‘Action’ as
As you have seen we decided the route (or you can say URL) over here only using annotations. Also we have mentioned the method as POST that meams the method will be called when the given route is called with the ‘POST’ method. We can check the response but in order to do that we have to start our server. So we are starting our server with the following comand
Now as our server is started just hit the “http://127.0.0.1:8000/api/create” but you cant just hit the request in your server. You can use various addons for REST, there are many available just search for them on Google.
Thats our API ready but lets now create a roe in our database using it. Here we have a entity User already in my database with five fields
So you have to send these in your request as POST body. So we will catch all these values from request in our createuserAction() as
So we have all the data we need to create a user so we are going to create a new User object and the will flush (commit) the object in our database and change the response as ‘USER IS CREATED’
And here you go run that API and get your reponse. You can also check in your database the value will be added. So thats it!! Happy Coding!!
Your email address will not be published. Required fields are marked*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
Excellent work, fast, good quality and understood the brief perfectly! Quick responses developing the project and very good cooperation. I suggest to anyone.
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.