1

I have an existing website using a fairly "standard" Symfony full-stack, using the Form component to display and process html forms.

Now, I am creating a REST API to retrieve and manipulate our resources, and I'll use the FOSRestBundle to help with that.

I want to offer nice error messages for the forms, and FOSRestBundle ships a default way to do that. Great.

My question is: should I use the SAME form classes I used in Web? Or should I duplicate all of the forms and start from scratch?

The API will need much of the same validation as Web, but some things like Captcha and CSRF are for sure different.

Thanks for any input on this.

1 Answer 1

1

It's a matter of taste.

If you have very different forms then it will be easy to do new form-classes. But if you have almost the same you can use your existing forms.

In one of my projects I had different fields in forms for API and Web but I had one Form class. I just check every time: is it API or Web. And manage fields according to the type of request.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.