Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7968621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:06:20+00:00 2026-06-04T07:06:20+00:00

After a bit of trial and error I managed to create the following function

  • 0

After a bit of trial and error I managed to create the following function in Yesod to grab an object from a JSON POST, create an EventFolder entity, and save it to the database.

postAddEventFolderR :: Handler RepJson
postAddEventFolderR = do
    r <- waiRequest 
    v <- liftIO . runResourceT $ requestBody r $$ sinkParser json
    let v1 :: EventFolder
        v1 = case fromJSON v of
                 Success a -> a
                 Error s   -> error s
    runDB $ insert $ v1
    return $ RepJson $ toContent $ show v1

The test function looks like curl -H "Content-Type: application/json" -X POST -d '{"name":"test_folder"}' http://localhost:5000/AddEventFolder.

The question is, well, first, is there a more concise way to write this function–it seems rather long-winded. And second, how could I extract a function that generically creates an object from the JSON? So I’d like to end up with something like

postAddEventFolderR = do
    v1 = extractEntityFromJsonPost (whatever params) :: EventFolder
    runDB $ insert $ v1
    return $ RepJson $ toContent $ show v1

Note I’m completely new to Haskell.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:06:21+00:00Added an answer on June 4, 2026 at 7:06 am

    I think the function you’re looking for is parseJsonBody_. Additionally, instead of using toContent and show, I think you’d want to use jsonToRepJson. So all together, you can probably express your code as:

    postAddEventFolderR = do
        v <- parseJsonBody_
        runDB $ insert (v :: EventFolder)
        jsonToRepJson v
    

    Though I’m not entirely certain why you’re responding with the data that the client just submitted.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

after a bit of searching I was unable to find a helpful post so...
After playing around with haskell a bit I stumbled over this function: Prelude Data.Maclaurin>
This question relates to my other post . Ok so after a bit more
I'm after a bit of advice on how to handle a multi tenant site
After researching a bit how the different way people slugify titles, I've noticed that
After reading a bit on Javascript's prototypical inheritance model , I change my style
i have philosophised about the purpose of stack a little bit and after some
Im skinning a progressBar in Flex, and after reading a bit about it, I
Edit: Prepare my objects for the use within a HashMap. after reading a bit
After playing quite a bit of Bad Company 2 over the last month, I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.