How to create an entity from a custom POST request in Drupal 8 (JSON:API or REST)?

by Tim Broeker   Last Updated August 13, 2019 03:07 AM - source

I've figured out the basics of how to use a simple POST request to create a new Drupal 8 node. For example, using the JSON:API:

https://www.drupal.org/docs/8/modules/jsonapi/creating-new-resources-post#basic-post-request with a payload that looks like:

{
  "data": {
    "type": "node--article",
    "attributes": {
      "title": "My custom title",
      "body": {
        "value": "Custom value",
        "format": "plain_text"
      }
    }
  }
}

However, in my case I have no control over the payload, and need to create a new node from a JSON post request that looks like so instead:

{
 "title": "My title",
 "message: "My Message",
}

The documentation and available examples for accepting POST requests I'm finding so far are few and far between, so just wondering if anybody has any guidance or examples to share.

I'm assuming we will need to implement a custom module of some sort to serialize/denormalize the payload, but the more I read the more I'm unclear about how to approach this or what exactly we need to implement. It has been a long day, and I'm just looking for the simplest approach to accepting a POST request like this to create a simple node :)

Thanks for any guidance -- Tim

Tags : json


Related Questions


How to use Icon8/webicons library with Drupal 7?

Updated May 04, 2016 08:03 AM

How to Logout a user using json?

Updated March 04, 2017 08:07 AM

Implementing schema.org

Updated May 18, 2017 17:07 PM

Disallow Json file in Drupal 7

Updated December 13, 2017 07:07 AM

How to return JSON data using Drupal 7

Updated August 22, 2015 17:03 PM