How to design your REST API endpoint

[A Thread]
https://twitter.com/thebiggergeek/status/1267205668408262663?s=21

Now let me clear this. Let’s say you’re calling Paystack API to charge a tokenised card.

If can either be “transaction successful” or “insufficient funds” you will need to different between these using the Boolean. https://twitter.com/thebiggergeek/status/1267205668408262663
After all from Paystack, the only success you need is “Transaction successful”.

It could be success and your customer has insufficient funds or card has expired.
With permission from @mykeels

Summary: status key wouldn’t be necessary if you return the right startup code for everything.

There’s a status code for every scenario
Moral lesson:

• Always return the right status code
• Structure your response object properly
• Avoid unnecessary data nesting

P.S: I may be wrong, please correct me.
You can follow @ichtrojan.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: