Is it really impossible to post complex JSON parameters with Restangular?

Is it possible to send a complex JSON object to a PUT route using Restangular?

    Restangular.one('model3ds', model.uuid).put(
       api_key: "blabla"
       model3d: { is_public: true }
    )

However, the data sent by Restangular appears as:

api_key: "blabla"
model3d: "{\"is_public:\":true}"

Has anyone found a way to change this behavior?

Please note that I can achieve this with single properties but not with an entire object.

    Restangular.one('model3ds', model.uuid).put(
        "model3d[is_public]": true
    )

Answer №1

Success! I have discovered the solution, which happens to be quite complex! The key lies within the custom keyword ;)

Restangular.one('model3ds', model.uuid).customPUT(
   api_key: "blabla"
   model3d: { is_public: true }
)

Answer №2

A different approach that doesn't involve using customPUT is to pass the object as the second parameter of the put method. For instance:

var object = {
    api_key: "blabla"
    model3d: { is_public: true }
};
Restangular.one('model3ds', model.uuid).put(null, object);

For more information, check out this resource:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unanticipated Behavior in JavaScript (jQuery): Triggering a Function Instead of Submitting a Form

I'm confused about something. Here's my issue: I have a specific type of form declaration where jQuery processes the form data and sends an Ajax request. Inside the form, there are buttons - one for form submission (Ajax) and another for calling ...

What steps should I take to prompt Postman to interact with a Web API?

I have recently installed the Postman plugin for Chrome and I am curious about how to use it to call my web API. Currently, I am making an AJAX call in JavaScript with the following code: alert("Getting security token"); // Do AJAX call to get security t ...

Attempting to retrieve a stream buffer from a function

I am currently working on creating a zip file that contains a CSV file and returning it as a buffer from a function. Below is the code snippet I have implemented: const archiver = require('archiver'); const streamBuffers = require("stream-bu ...

Modifying Copyright Feature in Footer

I am attempting to implement this function within my dark-colored footer: import Typography from '@material-ui/core/Typography'; function Copyright() { return ( <Typography variant="body2" color="textSecondary" align="center"> ...

Printing the selected value from a drop-down box in HTML with JavaScript

I'm in the process of creating a web page structured like this: <html> <head> <title>Bug UI</title> </head> <body> <script> function myfunc() { //what should I include here?? } </script> <form> ...

Obtain the name of a node using its identification number in D3JS

I am currently working on implementing a generalized tooltip feature. This tooltip will display the name and other relevant data of the active node. For example, if node 3 is currently active, the tooltip will show the name and distance (not link distance) ...

Error: Attempting to access property 'setData' of an undefined object results in a TypeError [Slider]

I encountered an error with my slider that says Uncaught TypeError: Cannot read property 'setData' of undefined. The error occurs when I use material ui as a component along with redux-form. This issue happens specifically when the slider is bein ...

Tips for extracting parameters from a URL using Express JS in a custom manner

Recently, I set up a server using the express package and encountered an issue while trying to extract parameters from the URL in a specific format. The URL structure is as follows: (notice there's no '?' indicating parameters). I am lookin ...

What are the best practices for integrating QML with Java?

How can QML be interfaced with Java when developing the GUI and API for a linux based device? ...

Create a modal using the base of a[href^=“#id”]

What is the best way to minimize a call modal window? $('#button-1').on('click', function() { $('#modal-1').addClass('j-modal--open'); }); $('#button-2').on('click', function() { $(' ...

Is there a way to verify if a user has selected the correct answer in a quiz program?

Here we have code segments in ajax, javascript, html, and an xml file. I'm looking to calculate the total score based on user input to determine if they selected the correct answers for a test. I've attempted to figure this out, but I'm str ...

Check if the number field in the If statement is empty or contains an excessive number of decimal places, while excluding cases where only zeroes are present in the decimal places

I am currently working with the following line of code: if ($val === "" || ($val.split(".")[1] || "").length > 2) With some assistance from the helpful individuals here, I have managed to implement this code successfully. ...

Lack of post data handling using Ajax, JQuery, Json, and Symfony 2

I have been attempting to send data in json format using JQuery Ajax, but I am unable to receive the posted data in the controller's action. Below is the JQuery/Javascript code snippet: $.ajax({ type: "POST", url: "app_dev.php/aj ...

`Write a custom AngularJS directive`

I followed the official AngularJS documentation to implement this directive. However, I am facing an issue with setting validity using the $setValidity() method in the link function of my directive. The changes are not reflecting in the view when I try to ...

Employ ImageMagic in a synchronous manner

Consider utilizing imagemagick Required to use imagemagick in a synchronous manner. Meaning the following code should execute only after the image conversion is complete (regardless of any errors). The only solution I can see involves using deasync: co ...

"Using the map function in Javascript to iterate through an array and then implementing

I am working on a script that involves an array of the alphabet along with two sets of values. The goal is to determine if a given value falls within the range specified by these two values and then print out the corresponding letter from the alphabet. H ...

Is it possible to modify a JavaScript array variable without having to refresh the page by utilizing Ajax?

Is it possible to update a JavaScript array variable without having to reload or refresh the page? I have an existing list of data in an array, and I retrieve additional data using PHP and Ajax. Now I want to add the new data obtained from PHP Ajax to th ...

What could be causing my .load() function to fail when attempting to target a specific div element?

My goal is to retrieve and display a div tag from another aspx page within my container div. Here is the jQuery code: function GetDocumentInfo(url) { $('MyContainer').load(url + ".otherdiv"); } This operation is triggered by a click event. ...

Utilize the `addEventListener` and `removeEventListener` functions on the menu to

Why is my mobile menu not functioning correctly? The submenu should open on the first click and redirect to the parent URL on the second click, which works fine. However, when the window width increases to 768px or more, the submenu should appear on hover ...

Verifying password authenticity using AngularJS

Hi there! I'm currently troubleshooting some code that is meant to validate passwords with specific requirements, such as having a certain length and containing special characters. I've managed to set the correct password length, but I'm en ...