CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner: Re: [Master_Sergius] How to write simple API for my cgi script?: Edit Log


Aug 19, 2018, 8:31 AM

Views: 2531
Re: [Master_Sergius] How to write simple API for my cgi script?


Now I want to write simple API to use this script in console or other script. For example if I type: <host>/v1/get_words?word=<some_word>, I should get response in JSON format.
What I should use here?

With your first script, most simply, you could handle both GET and POST request methods, and add a new query parameter "json", which if true serializes the response data structure as json instead of html. But from your second script it looks as though you have handled this in your own way.

How to add this to my script properly? I can use $cgi->path_info, or CGI::Application::Dispatch, or some REST framework or something else??? And how?

As you are aware, CGI is outdated and basically deprecated. I recommend using a modern web application framework, one of what I call, "the big three", Dancer2, Mojolicious or Catalyst. There are others available such as CGI::Application::Dispatch that you mentioned, but those I listed are featuresome and there is much more support.

I recommend starting with Dancer2, its simpler to learn than the others. Its focus is specifically on interfacing the typically low level side of things, but there are various core engines that handle common components such as sessions and templates, and plugins that extend its functionality such as for form and database management.

In my opinion, to do it properly, you would need to look into the following (or equivalents), in order to replace your current application:

- Dancer2
- Template(::Toolkit) via Dancer2::Template::TemplateToolkit
- DBI via Dancer2::Plugin::Database
- HTML::FormHandler

And maybe:

- DBIx::Class via Dancer2::Plugin::DBIC


(This post was edited by Zhris on Aug 19, 2018, 8:36 AM)

Edit Log:
Post edited by Zhris (Enthusiast) on Aug 19, 2018, 8:36 AM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives