javascript rest api using prototype

JavaScript seems to be in my future, it looks like.  Plus a bunch of Warner Archive awesome cartoons on DVD, but I’ll get into that later.

I’ve been doing web design for a long time, but it hasn’t really gotten too interesting until I started playing with MVCs and JS frameworks and AJAX.  Now, all the *boring* stuff is totally out of the way, and the fun stuff is where I can see what I can quickly develop.  Kind of interesting really.  Plus, I think it’s kinda cool because I had pretty much sworn off getting more into computer tech, but this is one that really is interesting.  Well, for now, anyway.

So, I’m working on creating a REST API inside my MVC (using CodeIgniter), but on top of that, I’m writing a class that JavaScript can use to send calls to the REST API.  Here’s what I’ve come up with so far: link.

I’m really looking for some peer review on this thing .. the only thing you need to be familiar with is PrototypeJS and JavaScript, and it should make sense.  It doesn’t matter what REST API it sends stuff to.

I want to explain a couple of coding conventions though.

The get_rest_url() function is a protected method, which is kinda cool — I didn’t know until today you could do that with JavaScript.  If you created a REST  object named, then calling the function wouldn’t work.   You can only call it internally.  That’s why it’s in the constructor.

I should probably learn to use exceptions.  The concept of them just baffles me though, and I don’t really see the point of them when you can do things procedurally.  Whatever.  I’m holding out on being stubborn on this one.

The class supposes that your REST URL will accept the uniq identifer at the end.

The AJAX requests need to be synchronous, otherwise I couldn’t access the responses.  If someone knows a way to do both, I’d be glad to hear about it … synchronous and then using bind(this) on the function is the only option I’ve found.

That’s all I can think of.  Like I said, JS is not my strongest coding skill, so if anyone could do a once-over, it’d be nicely appreciated.

For what it’s worth, the code works just fine for my needs though. 🙂

1 comment on “javascript rest api using prototype

Leave a Reply