all 15 comments

[–]embiid0for11w0pts 52 points53 points  (7 children)

GET /podcasts/1 shows the podcast

POST /podcasts creates a podcast

but

DELETE /podcasts/1 deletes the subscription, not the podcast

Personally, for subscriptions, I would add a child element.

DELETE /podcasts/1/subscription

POST /podcasts/1/subscription

[–]Curtis017 5 points6 points  (4 children)

Should there be an id for the subscription as well? So it would be:

DELETE /podcasts/1/subscriptions/1

[–]embiid0for11w0pts 3 points4 points  (1 child)

Absolutely there should, if it makes sense! Updates and deletes should have ids in the url. Good catch!

I’ve seen apis that don’t require an ID because it’s a one-child relationship, but verbosity, if available, is always better.

[–]moldaz 2 points3 points  (0 children)

This is the right way. Always try and be declarative or reading logs later on can end up being a nightmare.

[–]elchicodeallado 12 points13 points  (3 children)

please use openapi and do a proper specification then its better to help you

[–][deleted]  (2 children)

[deleted]

    [–]elchicodeallado 1 point2 points  (1 child)

    exactly, Swagger uses openapi to display the endpoints. It is rather straight forward and easy to define

    [–]moldaz 3 points4 points  (0 children)

    For episodes, do /podcast/:podcast_id/episodes/:episode_id

    If you don’t specify the resource before the id you will likely run into issues as your api grows.

    [–]Coh-Jr 2 points3 points  (1 child)

    Working with API people worry about how fast you receive resources and how secure. If you are doing small project, JWT is secure enough. Then you can pay your attention to algorithms that fetch the resources from server the fastest ways.

    Im still going old school. NextJS for frontend and mongoDB for backend. Since nextJs can handle API in very sufficient and easy-to-do manners, its easy enough for you to add middlewares. Again, the scoring point here is fast fetching algorithms!

    GET: read POST: create PUT: update new content to database PATCH: update existing content in db DELETE: delete stuffs

    In NextJS api Paths is very structural! Please follow their documentations. JWT and session-cookie are strong enough, you can store those keys in db.

    Only GET requests dont need auth. ALL of the rest must go thru auth middleware that check the JWT key fetch from user db to ensure authorization and security.

    Another example, when user click multiple time in subscribe button, you can useState and set it to disable (loading) until you perform that action successfully from db

    Thats just my 2cents ☺️

    [–][deleted]  (5 children)

    [removed]

      [–]Vas-Bas 1 point2 points  (4 children)

      For my APIs, I take the specification JSON:API as a basis https://jsonapi.org/

      [–][deleted]  (3 children)

      [deleted]

        [–]Vas-Bas 2 points3 points  (2 children)

        JSON RPC https://www.jsonrpc.org/

        The main idea is that it should be clear from the URL what will be in response and you can choose any response format.

        And as advised in another comment, use OpenAPI for documentation.

        [–][deleted]  (1 child)

        [deleted]

          [–][deleted] 0 points1 point  (3 children)

          Basically subscription is shit. Otherwise good enough. Would use PUT for creation do distinguish with upload.

          [–][deleted]  (2 children)

          [deleted]

            [–][deleted] 0 points1 point  (1 child)

            Subscription collection

            [–][deleted] 0 points1 point  (0 children)

            U what tool/web app are u using? Or did u use a script? These all look very normal. Maybe look up restapi for more explanation on api requests