Contents
Should REST API contain business logic?
An API can be a front-end controller that receives the command from a user action or a REST Controller. The API is the facade. It should not contain the actual business logic of the task at hand. Instead, the real behavior should remain within the underlying Service class.
What is business logic in api?
Business logic is what happens between the user interaction and internal data persistence. It determines what data is to be collected from the user, how it’s stored, and where it goes. If APIs handle the what of your workflows, business logic handles the how.
Which data format does REST API uses?
The REST API supports the following data formats: application/json. application/json indicates JavaScript Object Notation (JSON) and is used for most of the resources. application/xml indicates eXtensible Markup Language (XML) and is used for selected resources.
What is API service layer?
A REST or Web services API layer offers a decoupled interface to data and/or functionality of one or more applications. Web services APIs offer a well-defined contract, called WSDL, that describes the services in terms of its operations and the data types used to exchange information. …
Is API a service layer?
The service layer provides capability servers owned by a telecommunication network service provider, accessed through open and secure Application Programming Interfaces (APIs) by application layer servers owned by third-party content providers.
Is it enough to validate an API request?
However, validation of our requests is not enough, unfortunately. In addition to validation, it is our responsibility to return the relevant messages and statuses to our API clients. I wanted to deal with these two things in this post.
What should business logic and input validation do?
Domain or business validation logic should do more than just report true or false. You want to enable the “user” of your business classes (ie the UI, or your logging system) to do something more than just report to the end-user that something is wrong. Now, how you do that is completely up to you.
Why do you need validation in the back end?
You generally want validation in your db because you generally want to ensure that your data is consistent and obeys certain constraints. You should validate in the back end because usually that is where the ‘truth’ about the business logic lies, and validating there can save needless trips to the db to save invalid data.
What is the difference between data validation and business rules validation?
Data validation is focused on verifying an atomic data item. Business rules validation is a more broad concept and more close to how business works and behaves. So it is mainly focused on behavior.