Strapi.service outside api?

Hi !

I’m a bit new and I’m still looking for some optimization in my code to have the best performance but, I’m crossing some problem of comprehension…
At first I pimped my editor. I’m currently using the tinyCME (quite enough easy to custom), So my use case is the following:

After create my preview to check the post before submit it, I make a function which parse the editor return (HTML) to change links and attributs (few details). But in the function that’s happen to have post’s id, and I should go to the post from the bdd to build the URL. Nothing to hard to do but I wanted to found my post obj with the following command :

const entity = await strapi.services.post.findOne({ slug });

but it’s acting like the command doesn’t working a bit annoying so I switch to the next command

let cta = await axios
     .get("http://localhost:1337/posts/" + id)
            .then((res) => res.data);

at the end I got the same result but in the first case I doesn’t pass trough a HTTP request…

While I’m working with strapi, I should have access to strapi.service ? (I’m right?)

PS : location of the custom editor (strapi/extensions/content-manager/admin/src/components)

Not from the admin panel, you have to run via rest as the admin panel is CSR React so it’s ran by the clients browser.

And the admin has it’s own REST controllers, if you go to the admin panel and open your dev-tools in the browser (network tab) you can see the requests being made. For example I have a model called test and the get request for a findOne looks like:

http://localhost:1337/content-manager/collection-types/application::test.test/1

The generic controller for the content-manager can be found here:

And you can see the route structure here:

At first thx @DMehaffy!

So if I understand how the admin panel is CSR React so we can’t call the REST controllers defined in the api folder (location strapi/api/whateverController/*.js). So expect the way I mention in the init question I can’t do more ‘better’ ?

I mean my purpose is to make something clean as you did for the admin panel editor (location extension folder where I custom my editor). So there is solutions that strapi already provide to call the REST controllers, instead of the https requests use to do when front talk with a server ? because I would like to shut all my api public routes.

I’m not sure if I’m enough clear… but step by step is the following:

  1. Create / Edit post on the admin panel ;
  2. Typing some text inside the post’s body (rich text) ;
  3. Press bellow the editor ‘Preview’ button (just display the HTML from the editor in a modal) ;

During the step 3, before render the HTML. I need to fetch from the BDD, posts mentioned. So I parse my HTML to find post’s ids and get then from bdd to have the most accurate preview.
It’s the moment where I need to access the REST api to get the data more efficiency (quickly, etc…) instead of making http request to do what I mentioned earlier and shut all my public route.

The content-manager plugin has it’s own separate API from the normal end-user routes. You can use the end-user routes but that’s not what they were intended for.