What is the definition of an "object"? Is it a single database record? Or maybe it's simply a noun? Why does it matter?
When building a CRUD API the thought is that a single API request is meant to impact a single object. Here again I ask, what is your definition of an "object"? Your answer will be different than others and as a result your APIs will be different.
When building a CRUD API the thought is that a single API request is meant to impact a single object. Here again I ask, what is your definition of an "object"? Your answer will be different than others and as a result your APIs will be different.
The invoice example....
An invoice is simple. It has some details and one or more line items on it. The basic database structure is one table for invoices and one table for line items. How do we create invoices with an API?
If you think "objects" are database records, then you will have two API endpoints. First you will create the invoice and wait for the response. That response will have the identifier for that newly created invoice. Next you create each line item (each being in its own api request) using that invoice identifier.
If you think "objects" are simply just nouns, then you will think of an invoice and its line items as a single object. To create an invoice, you would then only submit to a single API endpoint with the invoice and all of its line items.
Two different definitions, two massively different API implementations.
If you think "objects" are simply just nouns, then you will think of an invoice and its line items as a single object. To create an invoice, you would then only submit to a single API endpoint with the invoice and all of its line items.
Two different definitions, two massively different API implementations.
A situation for both of them....
Each have their pros and cons. Ultimately, your goal should be designing the best damn interface for you, your customers, and your team to interact with. Sacrificing usability to simply adhere to some made up "framework" based on made up definitions makes absolutely no sense. They are good ideas to keep in mind but remember, they are all made up anyways. The only one that knows your situation is you, not Smartass Programmer 823 on Stack Overflow telling you how to run your company and engineering.
Be willing to experiment, jump outside the box for a bit, test the limits of your understanding, and be willing to challenge the definitions the world puts on you.
Please do not send me responses with links to Wikipedia or other articles from "thought leaders" defining API design or object definition. All you are doing is trying to shove terms in peoples faces. It's rude. It's passive aggressive. It's all made up.
Be willing to experiment, jump outside the box for a bit, test the limits of your understanding, and be willing to challenge the definitions the world puts on you.
Please do not send me responses with links to Wikipedia or other articles from "thought leaders" defining API design or object definition. All you are doing is trying to shove terms in peoples faces. It's rude. It's passive aggressive. It's all made up.