Giter Site home page Giter Site logo

Comments (7)

jeevatkm avatar jeevatkm commented on May 2, 2024 3

Sure, I will add support for map for JSON content type.

from resty.

jeevatkm avatar jeevatkm commented on May 2, 2024 1

@moorara - It seems resty already supports map type.

I have created this test case method for resty. Have a look and share your thought.

func TestPostJSONResultMapSuccess(t *testing.T) {
	ts := createPostServer(t)
	defer ts.Close()

	c := dc()
	c.SetDebug(false)

	resp, err := c.R().
		SetBody(map[string]interface{}{"username": "testuser", "password": "testpass"}).
		SetResult(map[string]interface{}{}).
		Post(ts.URL + "/login")

	assertError(t, err)
	assertEqual(t, http.StatusOK, resp.StatusCode())

	result := (*resp.Result().(*map[string]interface{}))
	fmt.Println("result[id]:", result["id"])
	fmt.Println("result[message]:", result["message"])
}

Also added dereferencing for your code snippet. It works.

resp, err := resty.R().SetResult(map[string]interface{}{}).Get(url)
result := (*resp.Result().(*map[string]interface{}))
fmt.Printf("%+v", result["message"])

from resty.

jeevatkm avatar jeevatkm commented on May 2, 2024

@moorara can you please share your feedback?

from resty.

jeevatkm avatar jeevatkm commented on May 2, 2024

@ChristianLohmann I saw thumps up for map support. Can you please see my above responses and share your feedback?

from resty.

ChristianLohmann avatar ChristianLohmann commented on May 2, 2024

Nice idea would appreciate to have. Is there also the demand of having slices marshaled to result? For me it would make sense to have response bodys like

[
  {
    "prop1": {},
    "prop2": "",
    "prop3": 1,
    "prop4": []
  }
]

automatically get unmarshaled to result.

from resty.

jeevatkm avatar jeevatkm commented on May 2, 2024

@ChristianLohmann - actually resty already supports map. Key point is; you have to dereference it before using a map.

resp, err := resty.R().SetResult(map[string]interface{}{}).Get(url)
result := (*resp.Result().(*map[string]interface{}))
fmt.Printf("%+v", result["message"])

I have tested at my end for map and Can you please try and let me know?

from resty.

jeevatkm avatar jeevatkm commented on May 2, 2024

Since resty already has map support, it just user have to deference it before use.

I'm closing it. Thanks @moorara @ChristianLohmann

from resty.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.