Add WP REST API url directly from command line when "frontity create"


Our users are getting a difficult step to solve when they create their first project with frontity. It is not clear the URL of the WP REST API that should be set in the frontity.settings.js under the wp-source package configuration

There are also some community threads regarding this:

The DevRel team will improve the docs but we could also…


Setting the state.source.api value from the command line to improve the developer experience when creating Frontity projects

Possible solution

When we do npx frontity create my-frontity-project one of the questions that the CLI could ask could be:

(wpUrl) → What is the URL of the homepage of your Wordpress site (default= ?
(isWpCom) → Is it a site  (y/N)?

Use Case 1

  • isWpCom=no
  • wpUrl=

state.source.api =

Use Case 2

  • wpUrl=
  • isWpCom=yes (in this case this value could be automatically detected and avoid the second question)

state.source.api =

Use Case 3

  • wpUrl=
  • isWpCom=yes

(This specific combination of + isWpCom=yes will result in a subdomain format of REST API)

state.source.api =

Use Case 4

  • wpUrl=
  • isWpCom=yes (Paid plan w/ custom domain: Personal, Business…)

state.source.api =

Use Case 5

  • wpUrl=
  • isWpCom=yes (Business plan w/ plugins installed w/o custom domain)

state.source.api =

Use Case 6

  • wpUrl=https://localhost:4000
  • isWpCom=no

state.source.api = http://localhost:4000/wp-json

This is a very good idea. Could we also avoid the prompt by adding a command line switch such as npx frontity create my-frontity-project -a

How about also a -noprompt switch which will default to the mars-theme and reply N to the email signup question?

1 Like

I like it :+1:

There’s already a --no-prompt option, isnt’ there? →

Maybe I should read the docs a bit more carefully! :laughing: