Jump to content

Tutorial: Building a simple REST API in ProcessWire

Recommended Posts

Hi @ Fantomas,

On your website you are using a bootstrap css compiled down to only 7kb, so what's inside that is still of some advantage compared to hand coded css ?


Share this post

Link to post
Share on other sites

Hi @pwired,

a bit off-topic, but so what...

I use bootstrap to always have the grid and basic options available. Maybe this is not needed on my own page, but maybe I wanted to be prepared to release more content.

Is there a question which packages I use, or should this be an advice to code css without bootstrap?


Share this post

Link to post
Share on other sites

Hi Fantomas,

Thanks for jumping in. No it's just that in the past I was obsessed with css grids because I couldn´t code my own css grid. I must have tried all css grids out there. Nowadays, the more I write my own css grid, the less I see the overkill use of a css grid such as bootstrap or uikit, etc. The only use I still see for css grids like bootstrap, uikit, etc. is when you are working together with a group of coders where a consistent way of working is needed on the same project.

Share this post

Link to post
Share on other sites
1 hour ago, AndreasWeinzierl said:

is this tutorial still up to date?

It must be. ProcessWire almost never introduces breaking changes at API level. The API gets additions and bug fixes only.

Share this post

Link to post
Share on other sites
7 minutes ago, AndreasWeinzierl said:


Tough question 🙂 Have you seen this module? 


or this one as another related alternative:


Edited by szabesz
added Page Query Boss link
  • Like 2

Share this post

Link to post
Share on other sites
2 hours ago, AndreasWeinzierl said:

And it is still the best way to go?

From the API side it is still valid and working code. I don't think there is one best way to go. This tutorial shows one possible approach. There are many different other approaches possible. But at least it shows the basics of implementing a REST API.

You can also have a look at https://modules.processwire.com/modules/rest-api-profile/ which is the most recent approach I'm aware of.

  • Like 3

Share this post

Link to post
Share on other sites

@gebeer It was a great post. Just one addition to what you have written. In case someone has a multilingual website the route to api will become => http://mywebsite.com/en/api/pages/. Notice the addition of language key here (en).

  • Like 1

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Demo
      I'm a newbie to Process wire. I'm trying to pass the form values to a different URL (i.e to sales force). We have a RestAPI to do a post method with URL Prams. when we tested the rest API it works with static values. So, i select the the option called submit to another URL in actions tab in my form. 
      So now the issue is how can i pass the field values dynamically to the REST API prams on form submit?
      If their is any easy way to submit form details to sales force please advice.
      Thanks in advance!! 

    • By cosmicsafari
      Hi all,
      I have been asked by a client whether we can setup load balancing for their existing Processwire site.
      From my investigations on Google and within these forums, it definitely seems possible but as a newbie with a basic understanding of the subject im a bit lost.
      Does anyone know of any existing tutorials for settings up load balancing with PW?
      What items would need to be changed on their current stand alone install, is there a list of best practices worth consulting etc?
      As I understand it we would need to have some sort of copying mechanism (rsync script most likely) in order to make sure any uploaded assets are shared between the main server and the fallback ones, other than that im not sure what else would need to be ammended.
      Any thoughts/help would be greatly appreciated.
    • By Sten
      I'd like to participate to a documentation about the page flow in PW. I am still a beginner and still have difficulties to see the big picture but I could help to the writing.
      What is the flow when a page is displayed or created ? It would be fine to draw a scheme with every stage in which one can add hooks. Something to describe the flow in time.
      May be it exists.
      What do you think ?
    • By EyeDentify
      Simple example for loading template specific CSS file.
      This example asumes that you have your CSS file in a directory relative to template root.
      Also i use in the template a simple text field to hold the name of the CSS file i want to load.
      I call this field 'css_file'
      Use what you feel comfortable with.
      So in your header section of the DOM notice the "page specific CSS" part?
      Thats were the magic happens. What happens is that we check to see if the file exists in the CSS dir relative to template root.
      And if it does we load it. Simple and effective.
      I load all other CSS that is used all over the site in global_styles.css first.
      And make sure you load template specific last, because then you can easily override CSS in global.
      DOM header example:
      <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title><?PHP echo($page->title); ?></title> <!-- main CSS --> <link rel="stylesheet" href="<?PHP echo($config->urls->templates); ?>css/global_styles.css"> <!-- page specific CSS --> <?PHP /* Use relative path in file_exists() */ if(file_exists('css/' . $page->css_file)) { echo("<link rel=\"stylesheet\" href=\"{$config->urls->templates}css/{$page->css_file}\">"); } ?> </head> <body> Thats my way of doing it. I am sure there is plenty of more ways to do it. This is for the newbies or anyone that wants more options.
      Good luck with your CSS out there in Cyberspace.
      Cheers from EyeDentify
    • By ARG
      Hello, I am completely new at PW, (and Php) coming from another CMS.  I decided to try to understand the beast, before crafting anything.
      So, I started  from the beginning: the simple web site tutorial.
      I am trying to output the Home page with Head and footer included in. 
      Here is my Home page code:
      include("./includes/head.inc.php"); echo "<h1>{$page->title}</h1>"; include("./includes/scripts.inc.php"); include("./includes/foot.inc.php"); Here is my  Head.inc.php code:
      <?php require_once("./includes/functions.inc.php"); ?> <!doctype html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="description" content="<?php echo $pages->get("/site-settings/")->site_meta_description; ?>"> <title><?php echo $pages->get("/site-settings/")->site_meta_description;?></title> <link rel="stylesheet" href="<?php echo $config->urls->templates?>css/simplegrid.css" /> <link rel="stylesheet" href="<?php echo $config->urls->templates?>css/site.css" /> </head> <body> And this the message I got, when I try to view my page:
      Compile Error: require_once(): Failed opening required 'C:/wamp64/www/processwire-master/site/templates/includes/includes/functions.inc.php' (include_path='.;C:\php\pear') (line 1 of C:\wamp64\www\processwire-master\site\assets\cache\FileCompiler\site\templates\includes\head.inc.php)
      Any advice would be helpful
      Thank you for your time.
  • Create New...