Skip to content

[API] Endpoint for creating a new resource #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lpatmo opened this issue Jan 7, 2020 · 6 comments
Closed

[API] Endpoint for creating a new resource #19

lpatmo opened this issue Jan 7, 2020 · 6 comments
Assignees
Milestone

Comments

@lpatmo
Copy link
Member

lpatmo commented Jan 7, 2020

We need a resources/create endpoint that accepts the following JSON body:

{
      "id": "7e08e0b0-da77-11e9-95c3-d20089b01401",
      "title": "The Road to Learn React",
      "description": "This Book is your personal start of learning React and its ecosystem. You will learn plain React, transition from JavaScript ES5 to ES6, and build an application along the way. Afterward you are able to build your own applications and you are prepared to dive into the React ecosystem.",
      "url": "https://leanpub.com/the-road-to-learn-react",
      "referrer": "https://roadtoreact.com/",
      "credit": "Lynnea Sauvage ([email protected])",
      "date_published": "2019-09-18T17:50:36-07:00",
      "created": "2019-09-18T17:50:36.198968-07:00",
      "modified": "2019-09-18T17:50:36-07:00",
      "media_type": "Book",
      "paid": true,
      "tags": [
        {
          "id": "a1167632-abb8-4ce1-b090-b84e79c94c7f",
          "name": "JavaScript"
        },
        {
          "id": "66cc3539-6705-45ee-b15d-644d5fb90c41",
          "name": "ES6"
        },
        {
          "id": "8b99bcd9-a9a5-4455-b2da-fed06051d502",
          "name": "React"
        }
      ]
    }

POSTing to resources/create should result in new resource being created.

@BethanyG
Copy link
Member

BethanyG commented Jan 7, 2020

Turns out, this is already taken care of since the endpoint was also set up to accept POST. You can create a resource by POST-ing to /api/v1/resources/ (using https://github.com/BethanyG/django-concept/tree/issue-18).

As currently set up, you will need a valid JWT token in your header in this format:

"Authorization: Bearer <your_token>"

@BethanyG
Copy link
Member

BethanyG commented Jan 7, 2020

I'll leave this open for now..just in case I am missing something.

@BethanyG BethanyG self-assigned this Jan 7, 2020
@BethanyG BethanyG added the needs discussion The fix for this issue needs discussion label Jan 7, 2020
@BethanyG BethanyG assigned lpatmo and BethanyG and unassigned BethanyG Jan 7, 2020
@BethanyG
Copy link
Member

BethanyG commented Jan 8, 2020

DRF does provide an automatic create/ endpoint, but it only accepts PUT requests, and I can't seem to figure out how to make it play nice without completely customizing the router class.

@lpatmo
Copy link
Member Author

lpatmo commented Jan 14, 2020

but it only accepts PUT requests

Do you mean that you want to make it accept PATCH requests instead of PUT?

I'm tempted to close this issue since I've tested that POST requests will work. :)

@BethanyG BethanyG removed the needs discussion The fix for this issue needs discussion label Jan 14, 2020
@BethanyG
Copy link
Member

Unless we have our hearts set on a specific api/v1/resources/create path that accepts POST I am inclined to agree with you: we close this, and call it done with api/v1/resources/ accepting POST requests.

@lpatmo
Copy link
Member Author

lpatmo commented Jan 14, 2020

Sounds good! Closing.

@lpatmo lpatmo closed this as completed Jan 14, 2020
@billglover billglover added this to the resources milestone Feb 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants