http.request error?

I just started working on a live-updating chat room for Codea (We’ll see how that turns out.), using http.request for connections and a raw GitHub gist as the server. Basically, I ran into a problem very fast. When I try and send a bit of text back to the server, it wasn’t working. I used another project to display the status & headers of the HTTP request, and found that when (Note, the same URL) I use the GET method, it returns the text fine (200). When I use the PUT method (Or POST or PATCH), it returns File Not Found (404). Why is this happening and how is it even possible? From what I know of HTTP requests, the same URL shouldn’t return 200 on one method and 404 on the other.

Funny I was just thinking about writing a chat program as well using a SQLdb. The github idea is interesting but the problem is that you would need a shared gist account between all users (to allow edit). If you’d like I could take a look at the code.

Oh, I totally forgot about using MySQL as the server. I might do that later… Here’s my W.I.P. code, anyway. https://gist.github.com/SkyTheCoder/67406f2b6dc7f1ca4511

Just on a quick look through. You need to make the api call to the api. Also use json to package the infor before sending and to unpackage it when you recieve.

https://api.github.com/gists/yourgistid

http://developer.github.com/v3/gists/
Give that a read through. You also need to authenticate if you are using POST/PATCH.

Okay… I think I understand how to edit a gist, but I don’t know how to work the JSON decoder, or encoder. Could you make a small example of creating/editing a gist file with the JSON module?

I pulled your data down just fine. All you need to know with json is to create a table with params to pass. then do output = json.decode(table) When you recieve data then do table = json.decode(data) that will give you a table will all the return info.

This is the decoded json output from a get

description: 
 forks_url: https://api.github.com/gists/b09cd401cc606277e723/forks
 comments: 0
 git_push_url: https://gist.github.com/b09cd401cc606277e723.git
 url: https://api.github.com/gists/b09cd401cc606277e723
 comments_url: https://api.github.com/gists/b09cd401cc606277e723/comments
 user:
    followers_url: https://api.github.com/users/SkyTheCoder/followers
    gists_url: https://api.github.com/users/SkyTheCoder/gists{/gist_id}
    repos_url: https://api.github.com/users/SkyTheCoder/repos
    gravatar_id: c63a6ce8510551f2af6ff27eb9938459
    html_url: https://github.com/SkyTheCoder
    events_url: https://api.github.com/users/SkyTheCoder/events{/privacy}
    type: User
    starred_url: https://api.github.com/users/SkyTheCoder/starred{/owner}{/repo}
    received_events_url: https://api.github.com/users/SkyTheCoder/received_events
    subscriptions_url: https://api.github.com/users/SkyTheCoder/subscriptions
    avatar_url: https://secure.gravatar.com/avatar/c63a6ce8510551f2af6ff27eb9938459?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png
    organizations_url: https://api.github.com/users/SkyTheCoder/orgs
    following_url: https://api.github.com/users/SkyTheCoder/following{/other_user}
    url: https://api.github.com/users/SkyTheCoder
    login: SkyTheCoder
    id: 4.61453e+06
 id: b09cd401cc606277e723
 created_at: 2013-07-13T00:01:24Z
 git_pull_url: https://gist.github.com/b09cd401cc606277e723.git
 updated_at: 2013-07-13T00:01:25Z
 history:
    1:
       version: e916a36d1209d800443129bee8023a0a177f013b
       user:
          followers_url: https://api.github.com/users/SkyTheCoder/followers
          gists_url: https://api.github.com/users/SkyTheCoder/gists{/gist_id}
          repos_url: https://api.github.com/users/SkyTheCoder/repos
          gravatar_id: c63a6ce8510551f2af6ff27eb9938459
          html_url: https://github.com/SkyTheCoder
          events_url: https://api.github.com/users/SkyTheCoder/events{/privacy}
          type: User
          starred_url: https://api.github.com/users/SkyTheCoder/starred{/owner}{/repo}
          received_events_url: https://api.github.com/users/SkyTheCoder/received_events
          subscriptions_url: https://api.github.com/users/SkyTheCoder/subscriptions
          avatar_url: https://secure.gravatar.com/avatar/c63a6ce8510551f2af6ff27eb9938459?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png
          organizations_url: https://api.github.com/users/SkyTheCoder/orgs
          following_url: https://api.github.com/users/SkyTheCoder/following{/other_user}
          url: https://api.github.com/users/SkyTheCoder
          login: SkyTheCoder
          id: 4.61453e+06
       url: https://api.github.com/gists/b09cd401cc606277e723/e916a36d1209d800443129bee8023a0a177f013b
       change_status:
          total: 1
          deletions: 0
          additions: 1
       committed_at: 2013-07-13T00:01:24Z
 public: false
 files:
    ChatRoomData:
       type: text/plain
       filename: ChatRoomData
       raw_url: https://gist.github.com/raw/b09cd401cc606277e723/6a58ae501cbc684e1cefd5c5dbbaf8145050edc6/ChatRoomData
       content: Does this message appear at the top of the chat room? Oh, well...
       size: 65
 commits_url: https://api.github.com/gists/b09cd401cc606277e723/commits
 html_url: https://gist.github.com/b09cd401cc606277e723
 forks:

What’s the syntax the table should be in, i.e. for

{
  "description": "the description for this gist",
  "files": {
    "file1.txt": {
      "content": "updated file contents"
    },
    "old_name.txt": {
      "filename": "new_name.txt",
      "content": "modified contents"
    },
    "new_file.txt": {
      "content": "a new file"
    },
    "delete_this_file.txt": null
  }
}

Could you give me an example of what this would look like as a table? (And would the format be the same when decoding JSON?)

Never mind on the last part of my comment, you posted the answer while I was writing it…

Edit: What decoded JSON looks like, I mean.

Decoded json is simply a lua table. Are you figuring it out?

I mean, could you write an example gist request and show it to me so I know how I should code it?

I don’t have time to work on it now but heres what i have. it simply pulls from your chat gist and prints the output. I included json for you.

https://gist.github.com/briarfox/7e766b72850f63a8ed05